mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-11-26 16:44:54 +00:00
feat: onbard junior by qrcode
This commit is contained in:
@ -8,6 +8,7 @@ import { CustomerService } from '~/customer/services';
|
||||
import { CreateJuniorRequestDto, SetThemeRequestDto } from '../dtos/request';
|
||||
import { Junior } from '../entities';
|
||||
import { JuniorRepository } from '../repositories';
|
||||
import { JuniorTokenService } from './junior-token.service';
|
||||
|
||||
@Injectable()
|
||||
export class JuniorService {
|
||||
@ -15,6 +16,7 @@ export class JuniorService {
|
||||
private readonly juniorRepository: JuniorRepository,
|
||||
private readonly userService: UserService,
|
||||
private readonly customerService: CustomerService,
|
||||
private readonly juniorTokenService: JuniorTokenService,
|
||||
) {}
|
||||
|
||||
@Transactional()
|
||||
@ -49,11 +51,11 @@ export class JuniorService {
|
||||
user,
|
||||
);
|
||||
|
||||
return this.findJuniorById(user.id, guardianId);
|
||||
return this.juniorTokenService.generateToken(user.id);
|
||||
}
|
||||
|
||||
async findJuniorById(juniorId: string, guardianId?: string) {
|
||||
const junior = await this.juniorRepository.findJuniorById(juniorId, guardianId);
|
||||
async findJuniorById(juniorId: string, withGuardianRelation = false, guardianId?: string) {
|
||||
const junior = await this.juniorRepository.findJuniorById(juniorId, withGuardianRelation, guardianId);
|
||||
|
||||
if (!junior) {
|
||||
throw new BadRequestException('JUNIOR.NOT_FOUND');
|
||||
@ -74,4 +76,14 @@ export class JuniorService {
|
||||
findJuniorsByGuardianId(guardianId: string, pageOptions: PageOptionsRequestDto) {
|
||||
return this.juniorRepository.findJuniorsByGuardianId(guardianId, pageOptions);
|
||||
}
|
||||
|
||||
async validateToken(token: string) {
|
||||
const juniorId = await this.juniorTokenService.validateToken(token);
|
||||
|
||||
return this.findJuniorById(juniorId, true);
|
||||
}
|
||||
|
||||
generateToken(juniorId: string) {
|
||||
return this.juniorTokenService.generateToken(juniorId);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user