Skip to content

Commit b02824a

Browse files
secure user db query
1 parent 6a8deb8 commit b02824a

File tree

2 files changed

+30
-25
lines changed

2 files changed

+30
-25
lines changed

src/controllers/users/users.controller.ts

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,30 @@ export class UsersController {
1515
return { msg: "created" };
1616
}
1717

18-
/*
19-
@Get(":id")
18+
19+
/*@Get(":id")
2020
@HttpCode(HttpStatus.FOUND)
2121
async get(@Param("id", ParseIntPipe) id: number): Promise<object> {
2222
return { data: await this.languageService.get(id) }
23-
}
24-
25-
@Get()
26-
@HttpCode(HttpStatus.FOUND)
27-
async list(@Query() params: any): Promise<object> {
28-
return { data: await this.languageService.list(params) }
29-
}
23+
}*/
24+
/*
25+
@Get()
26+
@HttpCode(HttpStatus.FOUND)
27+
async list(@Query() params: any): Promise<object> {
28+
return { data: await this.languageService.list(params) }
29+
}
30+
31+
@Put(":id")
32+
@HttpCode(HttpStatus.ACCEPTED)
33+
async update(@Param("id", ParseIntPipe) id: number, @Body(new JoiValidationPipe(createUserSchema)) payload: any): Promise<object> {
34+
return { msg: "updated", data: await this.languageService.update(id, payload) }
35+
}
3036
31-
@Put(":id")
32-
@HttpCode(HttpStatus.ACCEPTED)
33-
async update(@Param("id", ParseIntPipe) id: number, @Body(new JoiValidationPipe(createUserSchema)) payload: any): Promise<object> {
34-
return { msg: "updated", data: await this.languageService.update(id, payload) }
35-
}
36-
37-
@Delete(":id")
38-
@HttpCode(HttpStatus.OK)
39-
async delete(@Param("id", ParseIntPipe) id: number): Promise<object> {
40-
let deleted = await this.languageService.delete(id)
41-
return { msg: "deleted" }
42-
}
43-
*/
37+
@Delete(":id")
38+
@HttpCode(HttpStatus.OK)
39+
async delete(@Param("id", ParseIntPipe) id: number): Promise<object> {
40+
let deleted = await this.languageService.delete(id)
41+
return { msg: "deleted" }
42+
}
43+
*/
4444
}

src/services/user/user.service.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,13 @@ export class UserService {
1919
let element = this.userRepo.create({ username, email, password: pswHash })
2020
await this.userRepo.save(element)
2121
}
22-
/*async get(id: number): Promise<object> {
23-
const user = await this.userRepo.findOne(id);
22+
async get(id: number): Promise<object> {
23+
const user = await this.userRepo.findOne(
24+
{
25+
where: { id },
26+
select: ["username", "email", "role"]
27+
}
28+
);
2429
if (!user) {
2530
throw new NotFoundException(`${this.singular} with id ${id} not found`);
2631
}
@@ -32,7 +37,7 @@ export class UserService {
3237
creationDate: user.creationDate,
3338
}
3439
}
35-
40+
/*
3641
3742
async list(params): Promise<object> {
3843
const users = await this.userRepo.find();

0 commit comments

Comments
 (0)