feat: fetch post faster
This commit is contained in:
parent
bd24282d2b
commit
774d29d798
|
|
@ -22,7 +22,10 @@ import { Response } from 'express';
|
||||||
import { GetUserFromRequest } from '@gitroom/nestjs-libraries/user/user.from.request';
|
import { GetUserFromRequest } from '@gitroom/nestjs-libraries/user/user.from.request';
|
||||||
import { ShortLinkService } from '@gitroom/nestjs-libraries/short-linking/short.link.service';
|
import { ShortLinkService } from '@gitroom/nestjs-libraries/short-linking/short.link.service';
|
||||||
import { CreateTagDto } from '@gitroom/nestjs-libraries/dtos/posts/create.tag.dto';
|
import { CreateTagDto } from '@gitroom/nestjs-libraries/dtos/posts/create.tag.dto';
|
||||||
import { AuthorizationActions, Sections } from '@gitroom/backend/services/auth/permissions/permission.exception.class';
|
import {
|
||||||
|
AuthorizationActions,
|
||||||
|
Sections,
|
||||||
|
} from '@gitroom/backend/services/auth/permissions/permission.exception.class';
|
||||||
|
|
||||||
@ApiTags('Posts')
|
@ApiTags('Posts')
|
||||||
@Controller('/posts')
|
@Controller('/posts')
|
||||||
|
|
@ -111,6 +114,11 @@ export class PostsController {
|
||||||
return this._postsService.getOldPosts(org.id, date);
|
return this._postsService.getOldPosts(org.id, date);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Get('/group/:group')
|
||||||
|
getPostsByGroup(@GetOrgFromRequest() org: Organization, @Param('group') group: string) {
|
||||||
|
return this._postsService.getPostsByGroup(org.id, group);
|
||||||
|
}
|
||||||
|
|
||||||
@Get('/:id')
|
@Get('/:id')
|
||||||
getPost(@GetOrgFromRequest() org: Organization, @Param('id') id: string) {
|
getPost(@GetOrgFromRequest() org: Organization, @Param('id') id: string) {
|
||||||
return this._postsService.getPost(org.id, id);
|
return this._postsService.getPost(org.id, id);
|
||||||
|
|
|
||||||
|
|
@ -454,7 +454,7 @@ export const CalendarColumn: FC<{
|
||||||
publishDate: loadPost.actualDate || loadPost.publishDate,
|
publishDate: loadPost.actualDate || loadPost.publishDate,
|
||||||
};
|
};
|
||||||
|
|
||||||
const data = await (await fetch(`/posts/${post.id}`)).json();
|
const data = await (await fetch(`/posts/group/${post.group}`)).json();
|
||||||
const date = !isDuplicate
|
const date = !isDuplicate
|
||||||
? null
|
? null
|
||||||
: (await (await fetch('/posts/find-slot')).json()).date;
|
: (await (await fetch('/posts/find-slot')).json()).date;
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ export class PostsRepository {
|
||||||
integration: {
|
integration: {
|
||||||
select: {
|
select: {
|
||||||
providerIdentifier: true,
|
providerIdentifier: true,
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
publishDate: true,
|
publishDate: true,
|
||||||
},
|
},
|
||||||
|
|
@ -235,6 +235,24 @@ export class PostsRepository {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getPostsByGroup(orgId: string, group: string) {
|
||||||
|
return this._post.model.post.findMany({
|
||||||
|
where: {
|
||||||
|
group,
|
||||||
|
...(orgId ? { organizationId: orgId } : {}),
|
||||||
|
deletedAt: null,
|
||||||
|
},
|
||||||
|
include: {
|
||||||
|
integration: true,
|
||||||
|
tags: {
|
||||||
|
select: {
|
||||||
|
tag: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
getPost(
|
getPost(
|
||||||
id: string,
|
id: string,
|
||||||
includeIntegration = false,
|
includeIntegration = false,
|
||||||
|
|
|
||||||
|
|
@ -252,6 +252,47 @@ export class PostsService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getPostsByGroup(orgId: string, group: string) {
|
||||||
|
const convertToJPEG = false;
|
||||||
|
const loadAll = await this._postRepository.getPostsByGroup(orgId, group);
|
||||||
|
const posts = this.arrangePostsByGroup(loadAll, undefined);
|
||||||
|
|
||||||
|
return {
|
||||||
|
group: posts?.[0]?.group,
|
||||||
|
posts: await Promise.all(
|
||||||
|
(posts || []).map(async (post) => ({
|
||||||
|
...post,
|
||||||
|
image: await this.updateMedia(
|
||||||
|
post.id,
|
||||||
|
JSON.parse(post.image || '[]'),
|
||||||
|
convertToJPEG
|
||||||
|
),
|
||||||
|
}))
|
||||||
|
),
|
||||||
|
integrationPicture: posts[0]?.integration?.picture,
|
||||||
|
integration: posts[0].integrationId,
|
||||||
|
settings: JSON.parse(posts[0].settings || '{}'),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
arrangePostsByGroup(all: any, parent?: string): PostWithConditionals[] {
|
||||||
|
const findAll = all
|
||||||
|
.filter((p: any) =>
|
||||||
|
!parent ? !p.parentPostId : p.parentPostId === parent
|
||||||
|
)
|
||||||
|
.map(({ integration, ...all }: any) => ({
|
||||||
|
...all,
|
||||||
|
...(!parent ? { integration } : {}),
|
||||||
|
}));
|
||||||
|
|
||||||
|
return [
|
||||||
|
...findAll,
|
||||||
|
...(findAll.length
|
||||||
|
? findAll.flatMap((p: any) => this.arrangePostsByGroup(all, p.id))
|
||||||
|
: []),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
async getPost(orgId: string, id: string, convertToJPEG = false) {
|
async getPost(orgId: string, id: string, convertToJPEG = false) {
|
||||||
const posts = await this.getPostsRecursively(id, true, orgId, true);
|
const posts = await this.getPostsRecursively(id, true, orgId, true);
|
||||||
const list = {
|
const list = {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue