feat: onbard junior by qrcode

This commit is contained in:
Abdalhamid Alhamad
2024-12-15 16:46:49 +03:00
parent 7437403756
commit b0972f1a0a
28 changed files with 3274 additions and 29 deletions

View File

@ -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);
}
}