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

Revert "fix: get posts by profile" #969

Merged
merged 1 commit into from
Jul 22, 2024
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
2 changes: 1 addition & 1 deletion src/controllers/user/post.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export class UserPostController {
}

@intercept(PaginationInterceptor.BINDING_KEY)
@get('/user/profile//posts/{id}')
@get('/user/profile/{id}/posts')
@response(200, {
description: 'Array of Post model instances',
content: {
Expand Down
1 change: 0 additions & 1 deletion src/enums/method-type.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,4 @@ export enum MethodType {
UPDATEEXPERIENCE = 'updateExperience',
UPDATEPRIMARY = 'updatePrimary',
VERIFY = 'verify',
FINDBYPROFILE = 'findByProfile',
}
26 changes: 6 additions & 20 deletions src/interceptors/pagination.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ export class PaginationInterceptor implements Provider<Interceptor> {
) {
const {query} = await invocationCtx.get(RestBindings.Http.REQUEST);
const {pageNumber, pageLimit} = query;
const filter = await this.beforePagination(invocationCtx, query);

const filter = await this.beforePagination(invocationCtx, query);
const meta = await this.initializeMeta(invocationCtx, filter, [
Number(pageNumber),
Number(pageLimit),
Expand All @@ -123,7 +123,7 @@ export class PaginationInterceptor implements Provider<Interceptor> {
): Promise<Filter<AnyObject>> {
const methodName = invocationCtx.methodName as MethodType;
const controllerName = invocationCtx.targetClass.name as ControllerType;
const filter = this.initializeFilter(invocationCtx, methodName);
const filter = this.initializeFilter(invocationCtx);

switch (controllerName) {
case ControllerType.USER: {
Expand Down Expand Up @@ -594,16 +594,10 @@ export class PaginationInterceptor implements Provider<Interceptor> {
pageDetail: number[],
): Promise<MetaPagination> {
const controllerName = invocationCtx.targetClass.name as ControllerType;
let additionalData = invocationCtx.args[0];
if (
controllerName === ControllerType.USERPOST &&
invocationCtx.methodName === MethodType.FIND
)
additionalData = undefined;
const {count} = await this.metricService.countData(
controllerName,
filter,
additionalData,
invocationCtx.args[0],
);

const meta = pageMetadata([...pageDetail, count]);
Expand Down Expand Up @@ -635,17 +629,10 @@ export class PaginationInterceptor implements Provider<Interceptor> {
};
}

private initializeFilter(
invocationCtx: InvocationContext,
method: MethodType,
): AnyObject {
let num = 0;
if (method === MethodType.FINDBYPROFILE) {
num = 1;
}
private initializeFilter(invocationCtx: InvocationContext): AnyObject {
const filter =
invocationCtx.args[num] && typeof invocationCtx.args[num] === 'object'
? invocationCtx.args[num]
invocationCtx.args[0] && typeof invocationCtx.args[0] === 'object'
? invocationCtx.args[0]
: {where: {}};

filter.where = {...filter.where};
Expand Down Expand Up @@ -677,7 +664,6 @@ export class PaginationInterceptor implements Provider<Interceptor> {
}

if (methodName === MethodType.GETIMPORTERS) return 2;
if (methodName === MethodType.FINDBYPROFILE) return 1;
return 0;
}
}
7 changes: 0 additions & 7 deletions src/services/metric.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,13 +348,6 @@ export class MetricService {

case ControllerType.EXPERIENCEPOST:
case ControllerType.USERPOST:
if (additionalData) {
const newWhere = {
createdBy: additionalData,
banned: false,
};
return this.postRepository.count(newWhere);
}
case ControllerType.POST:
return this.postRepository.count(where);

Expand Down
2 changes: 1 addition & 1 deletion src/services/post.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,8 @@
id: string,
filter?: Filter<Post>,
): Promise<Post[]> {
const where = filter?.where ?? {createdBy: id};
return this.postRepository.find({
...filter,
where: {
createdBy: id,
},
Expand Down Expand Up @@ -401,7 +401,7 @@

private async beforeCreate(draftPost: DraftPost): Promise<void> {
let url = '';
let embeddedURL = null;

Check failure on line 404 in src/services/post.service.ts

View workflow job for this annotation

GitHub Actions / Test on Node.js 16 ( lint:check )

'embeddedURL' is never reassigned. Use 'const' instead

if (draftPost.text) {
const found = draftPost.text.match(
Expand Down
Loading