Skip to content

Commit

Permalink
Revert "fix: get posts by profile (#968)"
Browse files Browse the repository at this point in the history
This reverts commit a226514.
  • Loading branch information
RiXelanya authored Jul 22, 2024
1 parent a226514 commit 6aa05ee
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 30 deletions.
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 @@ export class PostService {
id: string,
filter?: Filter<Post>,
): Promise<Post[]> {
const where = filter?.where ?? {createdBy: id};
return this.postRepository.find({
...filter,
where: {
createdBy: id,
},
Expand Down

0 comments on commit 6aa05ee

Please sign in to comment.