Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Szotkowski committed Sep 22, 2023
1 parent d7dae81 commit 7d89bc1
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 54 deletions.
28 changes: 14 additions & 14 deletions src/controllers/instruction-step.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class InstructionStepController {
@repository(InstructionRepository)
public instructionRepository: InstructionRepository,
@repository(StepRepository) public stepRepository: StepRepository,
) {}
) { }

@authenticate('jwt')
@post('/users/{id}/instructions/{instructionId}/steps/{stepId}', {
Expand All @@ -48,8 +48,8 @@ export class InstructionStepController {
},
},
})
async create(
@param.path.number('id') instructionId: number,
async createStep(
@param.path.number('instructionId') instructionId: number,
@requestBody({
content: {
'application/json': {
Expand All @@ -76,7 +76,7 @@ export class InstructionStepController {
},
},
})
step: Omit<Step, 'id' | 'instructionId'>,
step: Omit<Step, 'id' | 'link' | 'deleteHash' | 'instructionId'>,
): Promise<Step> {
const user = await this.userRepository.findById(this.user.id);
if (!user) {
Expand Down Expand Up @@ -110,9 +110,9 @@ export class InstructionStepController {
},
},
})
async patch(
@param.path.number('stepId') stepId: number,
async patchStep(
@param.path.number('instructionId') instructionId: number,
@param.path.number('stepId') stepId: number,
@requestBody({
content: {
'application/json': {
Expand Down Expand Up @@ -160,7 +160,7 @@ export class InstructionStepController {
}

@authenticate('jwt')
@del('/users/{id}/instructions/{instructionId}/steps/{stepId}', {
@del('/users/{id}/instructions/{instructionId}/steps/${stepId}', {
responses: {
'200': {
description: 'Delete Step',
Expand All @@ -174,9 +174,9 @@ export class InstructionStepController {
},
},
})
async delete(
@param.path.number('stepId') stepId: number,
async deleteStep(
@param.path.number('instructionId') instructionId: number,
@param.path.number('stepId') stepId: number,
): Promise<boolean> {
const user = await this.userRepository.findById(this.user.id);
if (!user) {
Expand Down Expand Up @@ -239,7 +239,7 @@ export class InstructionStepController {
},
},
})
async getPublicInstructions(
async getSteps(
@param.path.number('instructionId') instructionId: number,
): Promise<Omit<Step, 'deleteHash'>[]> {
const user = await this.userRepository.findById(this.user.id);
Expand Down Expand Up @@ -274,9 +274,9 @@ export class InstructionStepController {
},
},
})
async uploadPicture(
@param.path.number('stepId') stepId: number,
async uploadStepsPicture(
@param.path.number('instructionId') instructionId: number,
@param.path.number('stepId') stepId: number,
@requestBody({
content: {
'multipart/form-data': {
Expand Down Expand Up @@ -335,9 +335,9 @@ export class InstructionStepController {
},
},
})
async deleteImage(
@param.path.number('stepId') stepId: number,
async deleteStepPicture(
@param.path.number('instructionId') instructionId: number,
@param.path.number('stepId') stepId: number,
): Promise<boolean> {
const user = await this.userRepository.findById(this.user.id);
if (!user) {
Expand Down
41 changes: 27 additions & 14 deletions src/controllers/user-instruction.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class UserInstructionController {
},
},
})
async create(
async createInstruction(
@requestBody({
content: {
'application/json': {
Expand Down Expand Up @@ -124,7 +124,7 @@ export class UserInstructionController {
},
},
})
async patch(
async patchInstruction(
@param.path.number('instructionId') instructionId: number,
@requestBody({
content: {
Expand Down Expand Up @@ -181,8 +181,8 @@ export class UserInstructionController {
},
},
})
async delete(
@param.query.number('instructionId') instructionId: number,
async deleteInstruction(
@param.path.number('instructionId') instructionId: number,
): Promise<boolean> {
const userOriginal = await this.userRepository.findById(this.user.id);
if (!userOriginal) {
Expand Down Expand Up @@ -280,14 +280,14 @@ export class UserInstructionController {
},
})
async getUsersInstructions(): Promise<{
instreuctions: Omit<Instruction, 'deleteHash' | 'premiumUserIds'>[];
instructions: Omit<Instruction, 'deleteHash' | 'premiumUserIds'>[];
progress: (Progress & ProgressRelations)[];
}> {
const user = await this.userRepository.findById(this.user.id);
if (!user) {
throw new HttpErrors.NotFound('User not found');
}
const instreuctions = await this.instructionRepository.find({
const instructions = await this.instructionRepository.find({
where: {
userId: this.user.id,
},
Expand All @@ -311,7 +311,7 @@ export class UserInstructionController {
userId: this.user.id,
},
});
return {instreuctions, progress};
return {instructions, progress};
}

@authenticate('jwt')
Expand All @@ -329,7 +329,7 @@ export class UserInstructionController {
},
},
})
async uploadPicture(
async uploadInstructionPicture(
@param.path.number('instructionId') instructionId: number,
@requestBody({
content: {
Expand Down Expand Up @@ -384,7 +384,7 @@ export class UserInstructionController {
},
},
})
async deleteImage(
async deleteInstructionPicture(
@param.path.number('instructionId') instructionId: number,
): Promise<boolean> {
const user = await this.userRepository.findById(this.user.id);
Expand Down Expand Up @@ -423,12 +423,25 @@ export class UserInstructionController {
},
},
})
async setPremium(
async setPremiumInstruction(
@param.path.number('instructionId') instructionId: number,
@requestBody()
@requestBody({
content: {
'application/json': {
schema: {
type: 'object',
properties: {
key: {type: 'string'},
premium: {type: 'boolean'},
},
required: ['key', 'premium'],
},
},
},
})
request: {
premium: boolean;
key: string;
premium: boolean;
},
): Promise<boolean> {
const user = await this.userRepository.findById(this.user.id);
Expand Down Expand Up @@ -482,6 +495,8 @@ export class UserInstructionController {
},
})
async authorizeUserToPremiumInstruction(
@param.path.number('instructionId') instructionId: number,
@param.path.number('userId') userId: number,
@requestBody({
content: {
'application/json': {
Expand All @@ -498,8 +513,6 @@ export class UserInstructionController {
request: {
key: string;
},
@param.query.number('instructionId') instructionId: number,
@param.query.number('userId') userId: number,
): Promise<boolean> {
const user = await this.userRepository.findById(this.user.id);
if (!user) {
Expand Down
10 changes: 5 additions & 5 deletions src/controllers/user-progress.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class UserProgressController {
},
},
})
async create(
async createProgress(
@requestBody({
content: {
'application/json': {
Expand Down Expand Up @@ -105,7 +105,7 @@ export class UserProgressController {
},
},
})
async patch(
async patchProgress(
@param.path.number('instructionId') instructionId: number,
@requestBody({
content: {
Expand Down Expand Up @@ -156,8 +156,8 @@ export class UserProgressController {
},
},
})
async delete(
@param.query.number('instructionId') instructionId: number,
async deleteProgress(
@param.path.number('instructionId') instructionId: number,
): Promise<boolean> {
const userOriginal = await this.userRepository.findById(this.user.id);
if (!userOriginal) {
Expand Down Expand Up @@ -199,7 +199,7 @@ export class UserProgressController {
},
},
})
async find(
async getProgress(
@param.path.number('instructionId') instructionId: number,
): Promise<Progress & ProgressRelations> {
const user = await this.userRepository.findById(this.user.id);
Expand Down
29 changes: 8 additions & 21 deletions src/controllers/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ export class UserController {
}

@authenticate('jwt')
@del('/users/{id}', {
@del('/users/{id}/{password}', {
responses: {
'200': {
description: 'Delete user',
Expand All @@ -638,29 +638,14 @@ export class UserController {
},
})
async deleteUser(
@requestBody({
content: {
'application/json': {
schema: {
type: 'object',
properties: {
password: {type: 'string'},
},
required: ['password'],
},
},
},
})
request: {
password: string;
},
@param.path.password('password') password: string,
): Promise<boolean> {
const userOriginal = await this.userRepository.findById(this.user.id);
if (!userOriginal) {
throw new HttpErrors.NotFound('User not found');
}
const passwordMatched = await this.hasher.comparePassword(
request.password,
password,
userOriginal.passwordHash,
);
if (!passwordMatched) {
Expand Down Expand Up @@ -910,7 +895,9 @@ export class UserController {
},
},
})
async getUserDetail(@param.query.number('userId') userId: number): Promise<{
async getUserDetail(
@param.path.number('userId') userId: number
): Promise<{
user: Omit<
User,
| 'email'
Expand All @@ -927,8 +914,8 @@ export class UserController {
>;
followerCount: number;
followeeCount: number;
instructions: Omit<Instruction, 'deleteHash'>[];
instructionsPremium: Omit<Instruction, 'deleteHash'>[];
instructions: Omit<Instruction, 'deleteHash'>[] | null;
instructionsPremium: Omit<Instruction, 'deleteHash'>[] | null;
}> {
const user = await this.userRepository.findById(userId, {
fields: {
Expand Down

0 comments on commit 7d89bc1

Please sign in to comment.