-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathuser.service.ts
More file actions
50 lines (41 loc) · 1.5 KB
/
user.service.ts
File metadata and controls
50 lines (41 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { Injectable } from '@nestjs/common';
import { IUserService } from '../user.interface';
import { CustomerService } from "@customer/application/customer.service";
import { DriverService } from "@driver/application/driver.service";
import { BusinessService } from "@business/application/business.service";
import { UserDto } from '../presentation/user.dto';
import { AuthDto } from '../presentation/auth.dto';
@Injectable()
export class UserService {
private readonly userServices: {
[key: string]: IUserService;
} = {};
constructor(
private readonly customerService: CustomerService,
private readonly driverService: DriverService,
private readonly businessService: BusinessService,
) {
this.userServices.customer = customerService;
this.userServices.driver = driverService;
this.userServices.business = businessService;
}
async getOne(dto: UserDto): Promise<UserDto> {
const user = await this.userServices[dto.userType!].getOne(dto);
user && (user.userType = dto.userType);
return user;
}
async findOne(dto: UserDto): Promise<UserDto | null> {
const user = await this.userServices[dto.userType!].findOne(dto);
user && (user.userType = dto.userType);
return user ?? null;
}
async create(dto: UserDto) {
return this.userServices[dto.userType!].create(dto);
}
async update(dto: AuthDto) {
return await this.userServices[dto.userType!].update(dto);
}
toUserDto(user: any) {
return this.userServices[user.userType].toUserDto(user);
}
}