Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed post filter by experience & include users in experience #310

Merged
merged 1 commit into from
Dec 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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