Skip to content

Commit

Permalink
edit id as string to uuid
Browse files Browse the repository at this point in the history
  • Loading branch information
Szotkowski committed Sep 26, 2023
1 parent 8b4a138 commit 236cf06
Show file tree
Hide file tree
Showing 11 changed files with 121 additions and 116 deletions.
32 changes: 16 additions & 16 deletions src/controllers/instruction-step.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class InstructionStepController {
},
})
async createStep(
@param.path.number('instructionId') instructionId: number,
@param.path.string('instructionId') instructionId: string,
@requestBody({
content: {
'application/json': {
Expand Down Expand Up @@ -111,8 +111,8 @@ export class InstructionStepController {
},
})
async patchStep(
@param.path.number('instructionId') instructionId: number,
@param.path.number('stepId') stepId: number,
@param.path.string('instructionId') instructionId: string,
@param.path.string('stepId') stepId: string,
@requestBody({
content: {
'application/json': {
Expand Down Expand Up @@ -175,8 +175,8 @@ export class InstructionStepController {
},
})
async deleteStep(
@param.path.number('instructionId') instructionId: number,
@param.path.number('stepId') stepId: number,
@param.path.string('instructionId') instructionId: string,
@param.path.string('stepId') stepId: string,
): Promise<boolean> {
const user = await this.userRepository.findById(this.user.id);
if (!user) {
Expand Down Expand Up @@ -213,7 +213,7 @@ export class InstructionStepController {
steps: {
type: 'object',
items: {
id: {type: 'number'},
id: {type: 'string'},
titleCz: {type: 'string'},
titleEn: {type: 'string'},
descriptionCz: {
Expand All @@ -240,7 +240,7 @@ export class InstructionStepController {
},
})
async getSteps(
@param.path.number('instructionId') instructionId: number,
@param.path.string('instructionId') instructionId: string,
): Promise<Omit<Step, 'deleteHash'>[]> {
const user = await this.userRepository.findById(this.user.id);
if (!user) {
Expand Down Expand Up @@ -275,8 +275,8 @@ export class InstructionStepController {
},
})
async uploadStepsPicture(
@param.path.number('instructionId') instructionId: number,
@param.path.number('stepId') stepId: number,
@param.path.string('instructionId') instructionId: string,
@param.path.string('stepId') stepId: string,
@requestBody({
content: {
'multipart/form-data': {
Expand Down Expand Up @@ -336,8 +336,8 @@ export class InstructionStepController {
},
})
async deleteStepPicture(
@param.path.number('instructionId') instructionId: number,
@param.path.number('stepId') stepId: number,
@param.path.string('instructionId') instructionId: string,
@param.path.string('stepId') stepId: string,
): Promise<boolean> {
const user = await this.userRepository.findById(this.user.id);
if (!user) {
Expand Down Expand Up @@ -378,7 +378,7 @@ export class InstructionStepController {
steps: {
type: 'object',
items: {
id: {type: 'number'},
id: {type: 'string'},
titleCz: {type: 'string'},
titleEn: {type: 'string'},
descriptionCz: {
Expand All @@ -394,7 +394,7 @@ export class InstructionStepController {
},
},
link: {type: 'string'},
instructionId: {type: 'number'},
instructionId: {type: 'string'},
},
},
},
Expand All @@ -405,7 +405,7 @@ export class InstructionStepController {
},
})
async getPremiumInstructionDetail(
@param.path.number('instructionId') instructionId: number,
@param.path.string('instructionId') instructionId: string,
): Promise<Omit<Step, 'deleteHash'>[]> {
const user = await this.userRepository.findById(this.user.id);
if (!user) {
Expand Down Expand Up @@ -438,15 +438,15 @@ export class InstructionStepController {
}

private validateInstructionOwnership(instruction: Instruction): void {
if (Number(instruction.userId) !== Number(this.user.id)) {
if (instruction.userId !== this.user.id) {
throw new HttpErrors.Forbidden(
'You are not authorized to this instruction',
);
}
}

private validateStepOwnership(step: Step, instruction: Instruction): void {
if (Number(step.instructionId) !== Number(instruction.id)) {
if (step.instructionId !== instruction.id) {
throw new HttpErrors.Forbidden(
'You are not authorized to this instruction',
);
Expand Down
30 changes: 15 additions & 15 deletions src/controllers/user-instruction.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export class UserInstructionController {
},
})
async patchInstruction(
@param.path.number('instructionId') instructionId: number,
@param.path.string('instructionId') instructionId: string,
@requestBody({
content: {
'application/json': {
Expand Down Expand Up @@ -182,7 +182,7 @@ export class UserInstructionController {
},
})
async deleteInstruction(
@param.path.number('instructionId') instructionId: number,
@param.path.string('instructionId') instructionId: string,
): Promise<boolean> {
const userOriginal = await this.userRepository.findById(this.user.id);
if (!userOriginal) {
Expand Down Expand Up @@ -240,7 +240,7 @@ export class UserInstructionController {
instructions: {
type: 'object',
items: {
id: {type: 'number'},
id: {type: 'string'},
titleCz: {type: 'string'},
titleEn: {type: 'string'},
difficulty: {enum: Object.values(Difficulty)},
Expand All @@ -252,7 +252,7 @@ export class UserInstructionController {
steps: {
type: 'object',
items: {
id: {type: 'number'},
id: {type: 'string'},
titleCz: {type: 'string'},
titleEn: {type: 'string'},
descriptionCz: {
Expand Down Expand Up @@ -330,7 +330,7 @@ export class UserInstructionController {
},
})
async uploadInstructionPicture(
@param.path.number('instructionId') instructionId: number,
@param.path.string('instructionId') instructionId: string,
@requestBody({
content: {
'multipart/form-data': {
Expand Down Expand Up @@ -385,7 +385,7 @@ export class UserInstructionController {
},
})
async deleteInstructionPicture(
@param.path.number('instructionId') instructionId: number,
@param.path.string('instructionId') instructionId: string,
): Promise<boolean> {
const user = await this.userRepository.findById(this.user.id);
if (!user) {
Expand Down Expand Up @@ -424,7 +424,7 @@ export class UserInstructionController {
},
})
async setPremiumInstruction(
@param.path.number('instructionId') instructionId: number,
@param.path.string('instructionId') instructionId: string,
@requestBody({
content: {
'application/json': {
Expand Down Expand Up @@ -495,8 +495,8 @@ export class UserInstructionController {
},
})
async authorizeUserToPremiumInstruction(
@param.path.number('instructionId') instructionId: number,
@param.path.number('userId') userId: number,
@param.path.string('instructionId') instructionId: string,
@param.path.string('userId') userId: string,
@requestBody({
content: {
'application/json': {
Expand Down Expand Up @@ -553,19 +553,19 @@ export class UserInstructionController {
instructions: {
type: 'object',
items: {
id: {type: 'number'},
id: {type: 'string'},
titleCz: {type: 'string'},
titleEn: {type: 'string'},
difficulty: {enum: Object.values(Difficulty)},
link: {type: 'string'},
private: {type: 'boolean'},
premium: {type: 'boolean'},
date: {type: 'string'},
userId: {type: 'number'},
userId: {type: 'string'},
steps: {
type: 'object',
items: {
id: {type: 'number'},
id: {type: 'string'},
titleCz: {type: 'string'},
titleEn: {type: 'string'},
descriptionCz: {
Expand Down Expand Up @@ -668,15 +668,15 @@ export class UserInstructionController {
instructions: {
type: 'object',
items: {
id: {type: 'number'},
id: {type: 'string'},
titleCz: {type: 'string'},
titleEn: {type: 'string'},
difficulty: {enum: Object.values(Difficulty)},
link: {type: 'string'},
private: {type: 'boolean'},
premium: {type: 'boolean'},
date: {type: 'string'},
userId: {type: 'number'},
userId: {type: 'string'},
},
},
},
Expand Down Expand Up @@ -706,7 +706,7 @@ export class UserInstructionController {
}

private validateInstructionOwnership(instruction: Instruction): void {
if (Number(instruction.userId) !== Number(this.user.id)) {
if (instruction.userId !== this.user.id) {
throw new HttpErrors.Forbidden(
'You are not authorized to this instruction',
);
Expand Down
12 changes: 6 additions & 6 deletions src/controllers/user-link.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class UserLinkController {
},
})
async followUser(
@param.path.number('followeeId') followeeId: number,
@param.path.string('followeeId') followeeId: string,
): Promise<boolean> {
const user = await this.userRepository.findById(this.user.id);
if (!user) {
Expand Down Expand Up @@ -67,7 +67,7 @@ export class UserLinkController {
},
})
async unfollowUser(
@param.path.number('followeeId') followeeId: number,
@param.path.string('followeeId') followeeId: string,
): Promise<boolean> {
const user = await this.userRepository.findById(this.user.id);
if (!user) {
Expand Down Expand Up @@ -98,7 +98,7 @@ export class UserLinkController {
schema: {
type: 'object',
properties: {
id: {type: 'number'},
id: {type: 'string'},
username: {type: 'string'},
link: {type: 'string'},
},
Expand All @@ -109,7 +109,7 @@ export class UserLinkController {
},
})
async getFollowers(
@param.path.number('userId') userId: number,
@param.path.string('userId') userId: string,
@param.query.number('limit') limit: number = 10,
@param.query.number('offset') offset: number = 0,
): Promise<Partial<User[]>> {
Expand Down Expand Up @@ -153,7 +153,7 @@ export class UserLinkController {
schema: {
type: 'object',
properties: {
id: {type: 'number'},
id: {type: 'string'},
username: {type: 'string'},
link: {type: 'string'},
},
Expand All @@ -164,7 +164,7 @@ export class UserLinkController {
},
})
async getFollowees(
@param.path.number('userId') userId: number,
@param.path.string('userId') userId: string,
@param.query.number('limit') limit: number = 10,
@param.query.number('offset') offset: number = 0,
): Promise<Partial<User[]>> {
Expand Down
28 changes: 14 additions & 14 deletions src/controllers/user-progress.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ export class UserProgressController {
schema: {
type: 'object',
properties: {
instructionId: {type: 'number'},
stepId: {type: 'number'},
descriptionId: {type: 'number'},
instructionId: {type: 'string'},
stepId: {type: 'string'},
descriptionId: {type: 'string'},
time: {type: 'number'},
},
required: ['instructionId', 'stepId', 'descriptionId', 'time'],
Expand Down Expand Up @@ -106,15 +106,15 @@ export class UserProgressController {
},
})
async patchProgress(
@param.path.number('instructionId') instructionId: number,
@param.path.string('instructionId') instructionId: string,
@requestBody({
content: {
'application/json': {
schema: {
type: 'object',
properties: {
stepId: {type: 'number'},
descriptionId: {type: 'number'},
stepId: {type: 'string'},
descriptionId: {type: 'string'},
time: {type: 'number'},
},
},
Expand Down Expand Up @@ -157,7 +157,7 @@ export class UserProgressController {
},
})
async deleteProgress(
@param.path.number('instructionId') instructionId: number,
@param.path.string('instructionId') instructionId: string,
): Promise<boolean> {
const userOriginal = await this.userRepository.findById(this.user.id);
if (!userOriginal) {
Expand Down Expand Up @@ -187,11 +187,11 @@ export class UserProgressController {
schema: {
type: 'object',
properties: {
id: {type: 'number'},
instructionId: {type: 'number'},
stepId: {type: 'number'},
descriptionId: {type: 'number'},
userId: {type: 'number'},
id: {type: 'string'},
instructionId: {type: 'string'},
stepId: {type: 'string'},
descriptionId: {type: 'string'},
userId: {type: 'string'},
},
},
},
Expand All @@ -200,7 +200,7 @@ export class UserProgressController {
},
})
async getProgress(
@param.path.number('instructionId') instructionId: number,
@param.path.string('instructionId') instructionId: string,
): Promise<Progress & ProgressRelations> {
const user = await this.userRepository.findById(this.user.id);
if (!user) {
Expand All @@ -219,7 +219,7 @@ export class UserProgressController {
}

private validateProgressOwnership(progress: Progress): void {
if (Number(progress.userId) !== Number(this.user.id)) {
if (progress.userId !== this.user.id) {
throw new HttpErrors.Forbidden('You are not authorized to this progress');
}
}
Expand Down
Loading

0 comments on commit 236cf06

Please sign in to comment.