Skip to content

Commit

Permalink
fixed post filter by experience & include users in experience (#310)
Browse files Browse the repository at this point in the history
  • Loading branch information
abdulhakim2902 authored Dec 16, 2021
1 parent 31709f2 commit 83b4a46
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 8 deletions.
11 changes: 11 additions & 0 deletions src/interceptors/experience.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,17 @@ export class ExperienceInterceptor implements Provider<Interceptor> {
({userId} = await this.userExperienceRepository.findById(
userExperienceId,
));
break;
}

case MethodType.FINDBYID: {
const filter = invocationCtx.args[1] ?? {};

if (!filter.include) filter.include = ['users'];
else filter.include.push('users');

invocationCtx.args[1] = filter;
break;
}
}

Expand Down
36 changes: 32 additions & 4 deletions src/interceptors/pagination.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,25 @@ export class PaginationInterceptor implements Provider<Interceptor> {
filter.where = Object.assign(filter.where ?? {}, {id: {inq: userIds}});
}

if (
className === ControllerType.USEREXPERIENCE &&
Object.prototype.hasOwnProperty.call(filter.where, 'userId')
) {
const include = {
relation: 'experience',
scope: {
include: [
{
relation: 'users',
},
],
},
};

if (!filter.include) filter.include = [include];
else filter.include.push(include);
}

// Get pageMetadata
const {count} = await this.metricService.countData(
className,
Expand Down Expand Up @@ -504,19 +523,28 @@ export class PaginationInterceptor implements Provider<Interceptor> {

if (!friends.length && !topics.length && !personIds.length) return;

const joinTopics = topics.join('|');
const regexTopic = new RegExp(joinTopics, 'i');
// TODO: ignore html tag in query
const spaceTopics = topics
.map(tag => ` ${tag}"|"${tag} |"${tag}"| ${tag} `)
.join('|');
const regexSpaceTopics = new RegExp(spaceTopics, 'i');

return {
or: [
{
and: [{tags: {inq: topics}}, {visibility: VisibilityType.PUBLIC}],
},
{
and: [{title: regexTopic}, {visibility: VisibilityType.PUBLIC}],
and: [
{title: regexSpaceTopics},
{visibility: VisibilityType.PUBLIC},
],
},
{
and: [{text: regexTopic}, {visibility: VisibilityType.PUBLIC}],
and: [
{text: regexSpaceTopics},
{visibility: VisibilityType.PUBLIC},
],
},
{
and: [
Expand Down
11 changes: 7 additions & 4 deletions src/services/experience.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,11 @@ export class ExperienceService {
})
).map(e => e.requesteeId);

const joinTags = tags.join('|');
const regexTag = new RegExp(joinTags, 'i');
// TODO: ignore html tag in query
const spaceTags = tags
.map(tag => ` ${tag}"|"${tag} |"${tag}"| ${tag} `)
.join('|');
const regexSpaceTags = new RegExp(spaceTags, 'i');

return {
or: [
Expand All @@ -88,10 +91,10 @@ export class ExperienceService {
],
},
{
and: [{text: regexTag}, {visibility: VisibilityType.PUBLIC}],
and: [{text: regexSpaceTags}, {visibility: VisibilityType.PUBLIC}],
},
{
and: [{title: regexTag}, {visibility: VisibilityType.PUBLIC}],
and: [{title: regexSpaceTags}, {visibility: VisibilityType.PUBLIC}],
},
{
and: [
Expand Down

0 comments on commit 83b4a46

Please sign in to comment.