forked from Yara724/api
Initial commit after migration to gitea
This commit is contained in:
0
src/profile/dto/actor/profile.dto.ts
Normal file
0
src/profile/dto/actor/profile.dto.ts
Normal file
51
src/profile/dto/user/AddPlateDto.ts
Normal file
51
src/profile/dto/user/AddPlateDto.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
import { ApiProperty } from "@nestjs/swagger";
|
||||
import { PlatesDto } from "src/plates/dto/plate.dto";
|
||||
import { Plates } from "src/Types&Enums/plate.interface";
|
||||
|
||||
export class AddPlateDto {
|
||||
plateId: string;
|
||||
@ApiProperty({ type: String, required: true })
|
||||
nationalCodeOfInsurer: string;
|
||||
|
||||
@ApiProperty({ type: String, required: true })
|
||||
nationalCodeOfDriver: string;
|
||||
|
||||
@ApiProperty({ type: String, required: true })
|
||||
insurerLicense: string;
|
||||
|
||||
@ApiProperty({ type: String, required: true })
|
||||
driverLicense: string;
|
||||
|
||||
@ApiProperty({ type: PlatesDto, required: true })
|
||||
plate: Plates;
|
||||
|
||||
@ApiProperty({ type: Boolean, required: true })
|
||||
driverIsInsurer: boolean;
|
||||
|
||||
@ApiProperty({ type: Boolean, required: true, default: false })
|
||||
isNewCar: boolean;
|
||||
|
||||
@ApiProperty({ type: Boolean, required: true })
|
||||
userNoCertificate: boolean;
|
||||
|
||||
@ApiProperty({
|
||||
type: Number,
|
||||
required: true,
|
||||
})
|
||||
insurerBirthday: number;
|
||||
@ApiProperty({
|
||||
type: String,
|
||||
required: false,
|
||||
})
|
||||
driverBirthday: string | null;
|
||||
}
|
||||
|
||||
export class AddPlateProfileDto {
|
||||
plateId: string;
|
||||
|
||||
@ApiProperty({ type: PlatesDto, required: true })
|
||||
plate: Plates;
|
||||
|
||||
@ApiProperty({ type: String, required: true })
|
||||
nationalCodeOfInsurer: string;
|
||||
}
|
||||
25
src/profile/dto/user/profile.dto.ts
Normal file
25
src/profile/dto/user/profile.dto.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { ApiProperty } from "@nestjs/swagger";
|
||||
import { UserModel } from "src/users/entities/schema/user.schema";
|
||||
|
||||
export class ProfileUserRq {
|
||||
@ApiProperty({ required: true })
|
||||
id: string;
|
||||
}
|
||||
|
||||
export class ProfileUserRs extends UserModel {
|
||||
userId: string;
|
||||
fullName: string;
|
||||
constructor(profile: UserModel, carDetail) {
|
||||
super();
|
||||
this.userId = profile["_id"];
|
||||
this.fullName = profile.fullName;
|
||||
this.mobile = profile.mobile;
|
||||
this.plates = profile.plates || null;
|
||||
this.nationalCode = profile.nationalCode;
|
||||
this.birthDay = profile.birthDay;
|
||||
this.gender = profile.gender;
|
||||
this.plates = profile.plates;
|
||||
this.city = profile.city;
|
||||
// this.carDetail
|
||||
}
|
||||
}
|
||||
31
src/profile/dto/user/update-profile.dto.ts
Normal file
31
src/profile/dto/user/update-profile.dto.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { ApiProperty, ApiSchema } from "@nestjs/swagger";
|
||||
import { IsDateString } from "class-validator";
|
||||
|
||||
@ApiSchema({
|
||||
name: "Update user profile",
|
||||
description: "Users updates their profile via this API.",
|
||||
})
|
||||
export class UpdateUserProfileDtoRq {
|
||||
// @ApiProperty({})
|
||||
// mobile: string;
|
||||
@ApiProperty({
|
||||
type: "string",
|
||||
description: "Birth date of the user",
|
||||
example: "1999-03-05",
|
||||
nullable: true,
|
||||
})
|
||||
@IsDateString()
|
||||
birthDay: string;
|
||||
|
||||
@ApiProperty()
|
||||
gender?: "male" | "female";
|
||||
|
||||
@ApiProperty()
|
||||
city: string;
|
||||
|
||||
@ApiProperty()
|
||||
state: string;
|
||||
|
||||
@ApiProperty()
|
||||
address: string;
|
||||
}
|
||||
20
src/profile/profile.controller.spec.ts
Normal file
20
src/profile/profile.controller.spec.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { Test, TestingModule } from "@nestjs/testing";
|
||||
import { ProfileController } from "./profile.controller";
|
||||
import { ProfileService } from "./profile.service";
|
||||
|
||||
describe("ProfileController", () => {
|
||||
let controller: ProfileController;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
controllers: [ProfileController],
|
||||
providers: [ProfileService],
|
||||
}).compile();
|
||||
|
||||
controller = module.get<ProfileController>(ProfileController);
|
||||
});
|
||||
|
||||
it("should be defined", () => {
|
||||
expect(controller).toBeDefined();
|
||||
});
|
||||
});
|
||||
63
src/profile/profile.controller.ts
Normal file
63
src/profile/profile.controller.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
import {
|
||||
Controller,
|
||||
Get,
|
||||
Post,
|
||||
Body,
|
||||
Patch,
|
||||
Param,
|
||||
Delete,
|
||||
UseGuards,
|
||||
} from "@nestjs/common";
|
||||
import { ApiBearerAuth, ApiBody, ApiParam, ApiTags } from "@nestjs/swagger";
|
||||
import { GlobalGuard } from "src/auth/guards/global.guard";
|
||||
import { CurrentUser } from "src/decorators/user.decorator";
|
||||
import { Roles } from "src/decorators/roles.decorator";
|
||||
import { PlatesService } from "src/plates/plates.service";
|
||||
import { AddPlateDto, AddPlateProfileDto } from "./dto/user/AddPlateDto";
|
||||
import { UpdateUserProfileDtoRq } from "./dto/user/update-profile.dto";
|
||||
import { ProfileService } from "./profile.service";
|
||||
|
||||
@Controller("user/profile")
|
||||
@ApiTags("user")
|
||||
@ApiBearerAuth()
|
||||
@Roles()
|
||||
export class ProfileController {
|
||||
constructor(
|
||||
private readonly profileService: ProfileService,
|
||||
private readonly plateService: PlatesService,
|
||||
) {}
|
||||
|
||||
@Get()
|
||||
@UseGuards(GlobalGuard)
|
||||
async getProfile(@CurrentUser() user) {
|
||||
return await this.profileService.getProfileDetail(user.username);
|
||||
}
|
||||
|
||||
@Patch()
|
||||
@UseGuards(GlobalGuard)
|
||||
@ApiBody({ type: UpdateUserProfileDtoRq })
|
||||
async updateProfile(
|
||||
@CurrentUser() user,
|
||||
@Body() body: UpdateUserProfileDtoRq,
|
||||
) {
|
||||
return await this.profileService.updateProfile(user.username, body);
|
||||
}
|
||||
|
||||
@Post("plate")
|
||||
@UseGuards(GlobalGuard)
|
||||
@ApiBody({ type: AddPlateProfileDto })
|
||||
async addPlate(@CurrentUser() user, @Body() body: AddPlateDto) {
|
||||
console.log(
|
||||
"🚀 ~ file: profile.controller.ts:50 ~ ProfileController ~ addPlate ~ user:",
|
||||
user,
|
||||
);
|
||||
return await this.plateService.addPlate(user.sub, body);
|
||||
}
|
||||
|
||||
@Delete("plate/:id")
|
||||
@UseGuards(GlobalGuard)
|
||||
@ApiParam({ name: "id", required: true })
|
||||
async deletePlate(@Param("id") id) {
|
||||
return await this.plateService.deletePlate(id);
|
||||
}
|
||||
}
|
||||
12
src/profile/profile.module.ts
Normal file
12
src/profile/profile.module.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { Module } from "@nestjs/common";
|
||||
import { PlatesModule } from "src/plates/plates.module";
|
||||
import { UsersModule } from "src/users/users.module";
|
||||
import { ProfileController } from "./profile.controller";
|
||||
import { ProfileService } from "./profile.service";
|
||||
|
||||
@Module({
|
||||
imports: [UsersModule, PlatesModule],
|
||||
controllers: [ProfileController],
|
||||
providers: [ProfileService],
|
||||
})
|
||||
export class ProfileModule {}
|
||||
18
src/profile/profile.service.spec.ts
Normal file
18
src/profile/profile.service.spec.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { Test, TestingModule } from "@nestjs/testing";
|
||||
import { ProfileService } from "./profile.service";
|
||||
|
||||
describe("ProfileService", () => {
|
||||
let service: ProfileService;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [ProfileService],
|
||||
}).compile();
|
||||
|
||||
service = module.get<ProfileService>(ProfileService);
|
||||
});
|
||||
|
||||
it("should be defined", () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
});
|
||||
17
src/profile/profile.service.ts
Normal file
17
src/profile/profile.service.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { Injectable } from "@nestjs/common";
|
||||
import { UserDbService } from "src/users/entities/db-service/user.db.service";
|
||||
import { ProfileUserRs } from "./dto/user/profile.dto";
|
||||
|
||||
@Injectable()
|
||||
export class ProfileService {
|
||||
constructor(private readonly userDbService: UserDbService) {}
|
||||
|
||||
async getProfileDetail(username: string) {
|
||||
const userDetail = await this.userDbService.findOne({ username });
|
||||
return new ProfileUserRs(userDetail, {});
|
||||
}
|
||||
|
||||
async updateProfile(username: string, update) {
|
||||
return await this.userDbService.findOneAndUpdate({ username }, update);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user