Skip to content

Commit

Permalink
add progress to instruction get
Browse files Browse the repository at this point in the history
  • Loading branch information
Szotkowski committed Sep 14, 2023
1 parent e3b2563 commit 9b126d7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
9 changes: 7 additions & 2 deletions src/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ import {
import {ServiceMixin} from '@loopback/service-proxy';
import * as dotenv from 'dotenv';
import path from 'path';
import {PingController, UserController} from './controllers';
import {InstructionStepController, PingController, UserController, UserInstructionController, UserLinkController, UserProgressController} from './controllers';
import {DbDataSource} from './datasources';
import {
InstructionRepository,
ProgressRepository,
StepRepository,
UserLinkRepository,
UserRepository,
Expand Down Expand Up @@ -49,11 +50,15 @@ export class SelecroBackendApplication extends BootMixin(
this.component(JWTAuthenticationComponent);
this.controller(PingController);
this.controller(UserController);
this.controller(StepRepository);
this.controller(UserProgressController);
this.controller(UserLinkController);
this.controller(UserInstructionController);
this.controller(InstructionStepController);
this.repository(UserRepository);
this.repository(InstructionRepository);
this.repository(StepRepository);
this.repository(UserLinkRepository);
this.repository(ProgressRepository);
this.dataSource(DbDataSource);

this.bind('services.jwt.service').toClass(JWTService);
Expand Down
18 changes: 13 additions & 5 deletions src/controllers/user-instruction.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ import {
} from '@loopback/rest';
import {SecurityBindings, UserProfile} from '@loopback/security';
import * as dotenv from 'dotenv';
import {Difficulty, Instruction} from '../models';
import {Difficulty, Instruction, Progress, ProgressRelations} from '../models';
import {
InstructionRepository,
ProgressRepository,
StepRepository,
UserRepository,
} from '../repositories';
Expand All @@ -38,7 +39,9 @@ export class UserInstructionController {
@repository(InstructionRepository)
protected instructionRepository: InstructionRepository,
@repository(StepRepository) public stepRepository: StepRepository,
) {}
@repository(UserRepository)
protected progressRepository: ProgressRepository,
) { }

@authenticate('jwt')
@post('/users/{id}/instructions/{instructionId}', {
Expand Down Expand Up @@ -277,13 +280,13 @@ export class UserInstructionController {
},
})
async getUsersInstructions(): Promise<
Omit<Instruction, 'deleteHash' | 'premiumUserIds'>[]
{instreuctions: 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 data = await this.instructionRepository.find({
const instreuctions = await this.instructionRepository.find({
where: {
userId: this.user.id,
},
Expand All @@ -302,7 +305,12 @@ export class UserInstructionController {
premiumUserIds: false,
},
});
return data;
const progress = await this.progressRepository.find({
where: {
userId: this.user.id,
},
});
return {instreuctions, progress};
}

@authenticate('jwt')
Expand Down

0 comments on commit 9b126d7

Please sign in to comment.