Skip to content

Commit c35e3dd

Browse files
committed
fix: isLiked, isViewed and likes fixed
1 parent 8be409e commit c35e3dd

5 files changed

Lines changed: 19 additions & 14 deletions

File tree

src/controller/postController.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,19 +74,21 @@ export class PostController extends Controller {
7474
@Get()
7575
@Security('jwt', [])
7676
public async findAllPosts(
77+
@Request() req: TsoaRequest,
7778
@Query() tab: 'following' | 'recommendations' | 'highlights',
7879
@Query() since: string,
7980
@Query() page: number,
8081
@Query() quantity: number,
81-
@Query() userProfileId?: string
82+
@Query() authorId?: string
8283
) {
8384
return ControllerUtils.handleResponse(
8485
await this.postService.findAllPosts({
8586
tab,
8687
since,
8788
page,
8889
quantity,
89-
userProfileId
90+
authorId,
91+
userProfileId: req.user.userProfileId
9092
}), this
9193
)
9294
}

src/repository/postRepository.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,15 @@ export class PostRepository {
147147
since,
148148
page,
149149
quantity,
150-
userProfileId: authorId
150+
authorId,
151+
userProfileId
151152
}: {
152153
tab: 'following' | 'recommendations' | 'highlights';
153154
since: string;
154155
page: number;
155156
quantity: number;
156-
userProfileId?: string;
157+
authorId?: string;
158+
userProfileId: string;
157159
}) {
158160
const where = {
159161
authorId,
@@ -187,23 +189,22 @@ export class PostRepository {
187189
])
188190

189191
const postIds = postsData.map(post => post.id)
190-
191192
let userLikes: { postId: null | string }[] = []
192193
let userViews: { postId: string }[] = []
193194

194-
if (authorId) {
195+
if (userProfileId) {
195196
[userLikes, userViews] = await this.pg.$transaction([
196197
this.pg.like.findMany({
197198
where: {
198199
postId: { in: postIds },
199-
userProfileId: authorId
200+
userProfileId
200201
},
201202
select: { postId: true }
202203
}),
203204
this.pg.view.findMany({
204205
where: {
205206
postId: { in: postIds },
206-
userProfileId: authorId
207+
userProfileId
207208
},
208209
select: { postId: true }
209210
})
@@ -212,7 +213,7 @@ export class PostRepository {
212213

213214
const likedPostIds = new Set(userLikes.map(like => like.postId))
214215
const viewedPostIds = new Set(userViews.map(view => view.postId))
215-
216+
216217
const formatted = postsData.map(post => {
217218
const count = post._count
218219
delete (post as any)._count

src/service/postService.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,15 @@ export class PostService {
136136
return await this.postRepository.update({ postId, title, content, links, tags, images: uploadedImages, userProfileId })
137137
}
138138

139-
public async findAllPosts({ tab, since, page, quantity, userProfileId }: {
139+
public async findAllPosts({ tab, since, page, quantity, authorId, userProfileId }: {
140140
tab: 'following' | 'recommendations' | 'highlights';
141141
since: string;
142142
page: number;
143143
quantity: number;
144-
userProfileId?: string;
144+
authorId?: string;
145+
userProfileId: string;
145146
}) {
146-
return await this.postRepository.findAll({ tab, since, page, quantity, userProfileId })
147+
return await this.postRepository.findAll({ tab, since, page, quantity, authorId, userProfileId })
147148
}
148149

149150
public async findPostById({ postId: id, userProfileId }: { postId: string; userProfileId: string; }) {

src/tsoa/routes.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,11 +337,12 @@ export function RegisterRoutes(app: Router,opts?:{multer?:ReturnType<typeof mult
337337

338338
async function PostController_findAllPosts(request: ExRequest, response: ExResponse, next: any) {
339339
const args: Record<string, TsoaRoute.ParameterSchema> = {
340+
req: {"in":"request","name":"req","required":true,"dataType":"object"},
340341
tab: {"in":"query","name":"tab","required":true,"dataType":"union","subSchemas":[{"dataType":"enum","enums":["following"]},{"dataType":"enum","enums":["recommendations"]},{"dataType":"enum","enums":["highlights"]}]},
341342
since: {"in":"query","name":"since","required":true,"dataType":"string"},
342343
page: {"in":"query","name":"page","required":true,"dataType":"double"},
343344
quantity: {"in":"query","name":"quantity","required":true,"dataType":"double"},
344-
userProfileId: {"in":"query","name":"userProfileId","dataType":"string"},
345+
authorId: {"in":"query","name":"authorId","dataType":"string"},
345346
};
346347

347348
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa

src/tsoa/swagger.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@
502502
},
503503
{
504504
"in": "query",
505-
"name": "userProfileId",
505+
"name": "authorId",
506506
"required": false,
507507
"schema": {
508508
"type": "string"

0 commit comments

Comments
 (0)