Skip to content

Commit 9426963

Browse files
yofriadiYofriadi Yahya
andauthored
hotfix(team, idea): create team with role student & teacher, login to… (#90)
* hotfix(team, idea): create team with role student & teacher, login to see idea, order desc idea comment * fix(idea): order by updated_at desc Co-authored-by: Yofriadi Yahya <yofriadi.yahya@outlook.com>
1 parent c92e529 commit 9426963

File tree

4 files changed

+21
-5
lines changed

4 files changed

+21
-5
lines changed

src/api/controllers/idea.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,17 @@ export class IdeaController {
4747
params: commonParams,
4848
response: {200: ideaCommentSchema},
4949
},
50+
onRequest: authenticate,
5051
},
5152
})
5253
async getIdeaById(
53-
req: FastifyRequest<{Params: {id: string}}>,
54+
req: AuthenticatedRequest<{Params: {id: string}}>,
5455
): Promise<IdeaResponse> {
56+
const user = req.user?.user as User;
57+
const userFound = await this.userService.getOne({id: user.id});
58+
if (!userFound) {
59+
throw {statusCode: 400, message: 'Please login to see ideas'};
60+
}
5561
const idea = await this.ideaService.getOne({id: req.params.id});
5662
if (!idea) throw {statusCode: 404, message: 'Idea not found'};
5763

@@ -65,11 +71,17 @@ export class IdeaController {
6571
querystring: ideaQueryStringSchema,
6672
response: {200: paginatedIdeaSchema},
6773
},
74+
onRequest: authenticate,
6875
},
6976
})
7077
async getAllIdeas(
71-
req: FastifyRequest<{Querystring: IdeaQueryString}>,
78+
req: AuthenticatedRequest<{Querystring: IdeaQueryString}>,
7279
): Promise<PaginatedResponse<Idea>> {
80+
const user = req.user?.user as User;
81+
const userFound = await this.userService.getOne({id: user.id});
82+
if (!userFound) {
83+
throw {statusCode: 400, message: 'Please login to see ideas'};
84+
}
7385
const orderEnum = ['solutionType', 'solutionName', 'liked'];
7486
let sorts = '';
7587
if (req.query.sort) {

src/api/controllers/ideaUser.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,11 @@ export default class IdeaController {
8888
]);
8989

9090
if (!userFound) throw {statusCode: 404, message: 'User not found'};
91-
if (userFound.profile?.profileType !== 'student') {
92-
throw {statusCode: 400, message: 'User not student'};
91+
if (
92+
userFound.profile?.profileType !== 'student' &&
93+
userFound.profile?.profileType !== 'teacher'
94+
) {
95+
throw {statusCode: 400, message: 'User not student or teacher'};
9396
}
9497
if (userFoundOnTeam) {
9598
throw {statusCode: 400, message: 'User already on team'};

src/api/services/idea.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export default class IdeaService {
6464
.limit(limit)
6565
.offset(offset)
6666
.orderBy(orderBy)
67-
.addOrderBy('ideas.created_at', 'ASC')
67+
.addOrderBy('ideas.updated_at', 'DESC')
6868
.leftJoinAndSelect('ideas.problemArea', 'problemArea')
6969
.loadRelationCountAndMap('ideas.totalLikes', 'ideas.likes')
7070
.loadRelationCountAndMap('ideas.totalComments', 'ideas.comments')

src/api/services/ideaComment.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export default class IdeaCommentService {
3232
return this.repository
3333
.createQueryBuilder('ideaComment')
3434
.where('idea_id = :id', {id})
35+
.orderBy('ideaComment.created_at', 'DESC')
3536
.leftJoinAndSelect('ideaComment.user', 'user')
3637
.limit(limit)
3738
.offset(offset)

0 commit comments

Comments
 (0)