diff --git a/docs/profile-plate-retirement.md b/docs/profile-plate-retirement.md new file mode 100644 index 0000000..b947426 --- /dev/null +++ b/docs/profile-plate-retirement.md @@ -0,0 +1,12 @@ +# Retirement of profile plate management + +The saved-vehicle feature has been removed from user profiles in every flow (unversioned and V1–V6). + +- `POST /user/profile/plate` and `DELETE /user/profile/plate/:id` are removed from routing and Swagger. +- Profile GET/PATCH responses contain personal profile fields, without saved plates. +- Profile PATCH accepts only `birthDay`, `gender`, `city`, `state`, and `address`. Plate arrays and MongoDB update operators are rejected before a database write. +- The unused profile plate service, model registration, and saved-car detail pages have been removed. +- Existing stored records are preserved. No migration or collection deletion is performed. +- Case inquiry plate entry and the shared `AddPlateDto`/`PlatesDto` contracts remain available to the active case workflows. + +Verification: the route contract excludes exactly the two retired profile routes. Profile regression tests cover omitted historical plates, blocked direct/operator updates, and preserved personal updates. The full API suite also covers inquiry and expert handoff workflows. diff --git a/src/app.module.ts b/src/app.module.ts index 7d12807..4fb85b0 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -16,7 +16,6 @@ import { ExpertClaimModule } from "./expert-claim/expert-claim.module"; import { ExpertInsurerModule } from "./expert-insurer/expert-insurer.module"; import { CaseExpertReportModule } from "./case-expert-report/case-expert-report.module"; import { LookupsModule } from "./lookups/lookups.module"; -import { PlatesModule } from "./plates/plates.module"; import { ProfileModule } from "./profile/profile.module"; import { SandHubModule } from "./sand-hub/sand-hub.module"; import { SystemSettingsModule } from "./system-settings/system-settings.module"; @@ -54,7 +53,6 @@ import { PriceEstimationModule } from "./price-estimation/price-estimation.modul AuthModule, ClientModule, ProfileModule, - PlatesModule, RequestManagementModule, SandHubModule, SystemSettingsModule, diff --git a/src/expert-blame/expert-blame.module.ts b/src/expert-blame/expert-blame.module.ts index d118bfd..7149793 100644 --- a/src/expert-blame/expert-blame.module.ts +++ b/src/expert-blame/expert-blame.module.ts @@ -1,6 +1,5 @@ import { Module } from "@nestjs/common"; import { ClientModule } from "src/client/client.module"; -import { PlatesModule } from "src/plates/plates.module"; import { UsersModule } from "src/users/users.module"; import { ExpertBlameController } from "./expert-blame.controller"; import { ExpertBlameV2Controller } from "./expert-blame.v2.controller"; @@ -15,7 +14,6 @@ import { ClaimRequestManagementModule } from "src/claim-request-management/claim UsersModule, ClientModule, RequestManagementModule, - PlatesModule, SmsOrchestrationModule, ClaimRequestManagementModule, LookupsModule, diff --git a/src/plates/entites/db-service/plate.db.service.ts b/src/plates/entites/db-service/plate.db.service.ts deleted file mode 100644 index d022bb3..0000000 --- a/src/plates/entites/db-service/plate.db.service.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { InjectModel } from "@nestjs/mongoose"; -import { Model, Types } from "mongoose"; -import { PlatesModel } from "../schema/plate.schema"; - -export class PlateDbService { - constructor( - @InjectModel(PlatesModel.name) - private readonly plateModel: Model, - ) {} - - async create(plate: PlatesModel): Promise { - return await this.plateModel.create(plate); - } - - async findOne(plate: PlatesModel): Promise { - return await this.plateModel.findOne(plate); - } - - async findAndRemove(id: Types.ObjectId): Promise { - return await this.plateModel.findOneAndUpdate( - { _id: id }, - { isDelete: true }, - { upsert: true }, - ); - } -} diff --git a/src/plates/entites/schema/plate.schema.ts b/src/plates/entites/schema/plate.schema.ts deleted file mode 100644 index cbc8bb8..0000000 --- a/src/plates/entites/schema/plate.schema.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { Prop, Schema, SchemaFactory } from "@nestjs/mongoose"; - -@Schema({ collection: "plates", versionKey: false }) -export class PlatesModel { - @Prop({ required: true, unique: false }) - userId: string; - - @Prop({ type: "number", maxlength: 2 }) - leftDigits: number; - - @Prop({ type: "string", maxlength: 1 }) - centerAlphabet: string; - - @Prop({ type: "number", maxlength: 3 }) - centerDigits: number; - - @Prop({ type: "number", maxlength: 2 }) - ir: number; - - @Prop() - nationalCodeOfInsurer: string; -} - -export const PlatesSchema = SchemaFactory.createForClass(PlatesModel); diff --git a/src/plates/plates.module.ts b/src/plates/plates.module.ts deleted file mode 100644 index 53db18b..0000000 --- a/src/plates/plates.module.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { Module } from "@nestjs/common"; -import { MongooseModule } from "@nestjs/mongoose"; -import { ClientModule } from "src/client/client.module"; -import { PlateDbService } from "src/plates/entites/db-service/plate.db.service"; -import { SandHubModule } from "src/sand-hub/sand-hub.module"; -import { UsersModule } from "src/users/users.module"; -import { PlateNormalizerModule } from "src/utils/plate-normalizer/plate-normalizer.module"; -import { PlatesModel, PlatesSchema } from "./entites/schema/plate.schema"; -import { PlatesService } from "./plates.service"; - -@Module({ - imports: [ - UsersModule, - SandHubModule, - ClientModule, - PlateNormalizerModule, - MongooseModule.forFeature([ - { name: PlatesModel.name, schema: PlatesSchema }, - ]), - ], - providers: [PlatesService, PlateDbService], - exports: [PlatesService, PlateDbService], -}) -export class PlatesModule {} diff --git a/src/plates/plates.service.ts b/src/plates/plates.service.ts deleted file mode 100644 index 61c00a1..0000000 --- a/src/plates/plates.service.ts +++ /dev/null @@ -1,55 +0,0 @@ -import { - HttpException, - HttpStatus, - Injectable, - NotFoundException, -} from "@nestjs/common"; -import { Types } from "mongoose"; -import { PlateDbService } from "src/plates/entites/db-service/plate.db.service"; -import { AddPlateDto } from "src/profile/dto/user/AddPlateDto"; -import { PlateNormalizerService } from "src/utils/plate-normalizer/plate-normalizer.service"; - -@Injectable() -export class PlatesService { - constructor( - private readonly plateDbService: PlateDbService, - private readonly plateNormalizer: PlateNormalizerService, - ) {} - - async addPlate(currentUser, body: AddPlateDto) { - const { plate, nationalCodeOfInsurer } = body; - - const normalizedAlphabet = this.plateNormalizer.normalizePlateText( - String(plate.centerAlphabet || ""), - ); - const duplicate = await this.plateDbService.findOne({ - userId: currentUser, - leftDigits: plate.leftDigits, - centerAlphabet: normalizedAlphabet, - centerDigits: plate.centerDigits, - ir: plate.ir, - nationalCodeOfInsurer, - }); - - if (duplicate) - throw new HttpException("duplicate plate", HttpStatus.CONFLICT); - - const newPlateData = await this.plateDbService.create({ - ...plate, - centerAlphabet: normalizedAlphabet, - userId: currentUser, - nationalCodeOfInsurer: body.nationalCodeOfInsurer, - }); - - return { - message: "Plate successfully added", - plate: newPlateData, - }; - } - - async deletePlate(id: Types.ObjectId) { - const deleted = await this.plateDbService.findAndRemove(id); - if (!deleted) throw new NotFoundException("Plate not found"); - return { message: "Plate deleted successfully" }; - } -} diff --git a/src/profile/dto/user/AddPlateDto.ts b/src/profile/dto/user/AddPlateDto.ts index 1431c24..aa93e3b 100644 --- a/src/profile/dto/user/AddPlateDto.ts +++ b/src/profile/dto/user/AddPlateDto.ts @@ -1,16 +1,3 @@ -import { ApiProperty } from "@nestjs/swagger"; -import { PlatesDto } from "src/plates/dto/plate.dto"; -import { Plates } from "src/Types&Enums/plate.interface"; import { InquiryParticipantFieldsDto } from "src/common/dto/inquiry-participants.dto"; export class AddPlateDto extends InquiryParticipantFieldsDto {} - -export class AddPlateProfileDto { - plateId: string; - - @ApiProperty({ type: PlatesDto, required: true }) - plate: Plates; - - @ApiProperty({ type: String, required: true }) - nationalCodeOfInsurer: string; -} diff --git a/src/profile/dto/user/profile.dto.ts b/src/profile/dto/user/profile.dto.ts index 58ad24d..3e10ef9 100644 --- a/src/profile/dto/user/profile.dto.ts +++ b/src/profile/dto/user/profile.dto.ts @@ -6,20 +6,21 @@ export class ProfileUserRq { id: string; } -export class ProfileUserRs extends UserModel { +export class ProfileUserRs { userId: string; fullName: string; - constructor(profile: UserModel, carDetail) { - super(); + mobile: string; + nationalCode: string; + birthDay: string; + gender?: "male" | "female"; + city: string; + constructor(profile: UserModel) { 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 } } diff --git a/src/profile/profile.controller.spec.ts b/src/profile/profile.controller.spec.ts index 3b85cb2..58046df 100644 --- a/src/profile/profile.controller.spec.ts +++ b/src/profile/profile.controller.spec.ts @@ -1,7 +1,6 @@ import { Test, TestingModule } from "@nestjs/testing"; import { ProfileController } from "./profile.controller"; import { ProfileService } from "./profile.service"; -import { PlatesService } from "src/plates/plates.service"; import { JwtService } from "@nestjs/jwt"; describe("ProfileController", () => { @@ -12,7 +11,6 @@ describe("ProfileController", () => { controllers: [ProfileController], providers: [ { provide: ProfileService, useValue: {} }, - { provide: PlatesService, useValue: {} }, { provide: JwtService, useValue: {} }, ], }).compile(); diff --git a/src/profile/profile.controller.ts b/src/profile/profile.controller.ts index 8b60c7a..3162a56 100644 --- a/src/profile/profile.controller.ts +++ b/src/profile/profile.controller.ts @@ -1,19 +1,8 @@ -import { - Controller, - Get, - Post, - Body, - Patch, - Param, - Delete, - UseGuards, -} from "@nestjs/common"; -import { ApiBearerAuth, ApiBody, ApiParam, ApiTags } from "@nestjs/swagger"; +import { Controller, Get, Body, Patch, UseGuards } from "@nestjs/common"; +import { ApiBearerAuth, ApiBody, 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"; @@ -22,10 +11,7 @@ import { ProfileService } from "./profile.service"; @ApiBearerAuth() @Roles() export class ProfileController { - constructor( - private readonly profileService: ProfileService, - private readonly plateService: PlatesService, - ) {} + constructor(private readonly profileService: ProfileService) {} @Get() @UseGuards(GlobalGuard) @@ -42,18 +28,4 @@ export class ProfileController { ) { return await this.profileService.updateProfile(user.username, body); } - - @Post("plate") - @UseGuards(GlobalGuard) - @ApiBody({ type: AddPlateProfileDto }) - async addPlate(@CurrentUser() user, @Body() body: AddPlateDto) { - 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); - } } diff --git a/src/profile/profile.module.ts b/src/profile/profile.module.ts index c869ebb..e1f9483 100644 --- a/src/profile/profile.module.ts +++ b/src/profile/profile.module.ts @@ -1,11 +1,10 @@ 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], + imports: [UsersModule], controllers: [ProfileController], providers: [ProfileService], }) diff --git a/src/profile/profile.service.spec.ts b/src/profile/profile.service.spec.ts index 34ac887..d50cd67 100644 --- a/src/profile/profile.service.spec.ts +++ b/src/profile/profile.service.spec.ts @@ -4,6 +4,7 @@ import { UserDbService } from "src/users/entities/db-service/user.db.service"; describe("ProfileService", () => { let service: ProfileService; + let users: { findOne: jest.Mock; findOneAndUpdate: jest.Mock }; beforeEach(async () => { const module: TestingModule = await Test.createTestingModule({ @@ -20,9 +21,50 @@ describe("ProfileService", () => { }).compile(); service = module.get(ProfileService); + users = module.get(UserDbService); }); it("should be defined", () => { expect(service).toBeDefined(); }); + + it("does not expose historical saved plates in the profile", async () => { + users.findOne.mockResolvedValue({ + _id: "user-id", + fullName: "Test user", + mobile: "09120000000", + plates: [{ plateId: "historical-plate" }], + }); + const profile = await service.getProfileDetail("09120000000"); + expect(profile).toMatchObject({ userId: "user-id", fullName: "Test user" }); + expect(profile).not.toHaveProperty("plates"); + }); + + it.each([ + { plates: [{ plateId: "new-plate" }] }, + { $push: { plates: { plateId: "new-plate" } } }, + { $set: { plates: [] } }, + ])("cannot manage plates through the profile PATCH: %j", async (update) => { + await expect(service.updateProfile("09120000000", update)).rejects.toThrow( + "Only personal profile fields can be updated", + ); + expect(users.findOneAndUpdate).not.toHaveBeenCalled(); + }); + + it("still updates personal details without modifying saved data", async () => { + users.findOneAndUpdate.mockResolvedValue({ _id: "user-id", plates: [] }); + const update = { + birthDay: "1999-03-05", + gender: "male", + city: "Tehran", + state: "Tehran", + address: "Test address", + }; + const profile = await service.updateProfile("09120000000", update); + expect(users.findOneAndUpdate).toHaveBeenCalledWith( + { username: "09120000000" }, + { $set: update }, + ); + expect(profile).not.toHaveProperty("plates"); + }); }); diff --git a/src/profile/profile.service.ts b/src/profile/profile.service.ts index ff111cb..d2b6b7d 100644 --- a/src/profile/profile.service.ts +++ b/src/profile/profile.service.ts @@ -1,4 +1,4 @@ -import { Injectable } from "@nestjs/common"; +import { BadRequestException, Injectable } from "@nestjs/common"; import { UserDbService } from "src/users/entities/db-service/user.db.service"; import { ProfileUserRs } from "./dto/user/profile.dto"; @@ -8,10 +8,18 @@ export class ProfileService { async getProfileDetail(username: string) { const userDetail = await this.userDbService.findOne({ username }); - return new ProfileUserRs(userDetail, {}); + return new ProfileUserRs(userDetail); } async updateProfile(username: string, update) { - return await this.userDbService.findOneAndUpdate({ username }, update); + const allowedFields = ["birthDay", "gender", "city", "state", "address"]; + if (Object.keys(update).some((field) => !allowedFields.includes(field))) { + throw new BadRequestException("Only personal profile fields can be updated"); + } + const userDetail = await this.userDbService.findOneAndUpdate( + { username }, + { $set: update }, + ); + return new ProfileUserRs(userDetail); } } diff --git a/src/request-management/request-management.module.ts b/src/request-management/request-management.module.ts index 99683c9..4bd56dd 100644 --- a/src/request-management/request-management.module.ts +++ b/src/request-management/request-management.module.ts @@ -3,7 +3,6 @@ import { MongooseModule } from "@nestjs/mongoose"; import { MulterModule } from "@nestjs/platform-express"; import { ClaimRequestManagementModule } from "src/claim-request-management/claim-request-management.module"; import { ClientModule } from "src/client/client.module"; -import { PlatesModule } from "src/plates/plates.module"; import { BlameVideoDbService } from "src/request-management/entities/db-service/blame-video.db.service"; import { RequestManagementDbService } from "src/request-management/entities/db-service/request-management.db.service"; import { BlameRequestDbService } from "src/request-management/entities/db-service/blame-request.db.service"; @@ -69,7 +68,6 @@ import { CallCenterBlameV6Controller } from "./call-center-blame-v6.controller"; HashModule, PlateNormalizerModule, WorkflowStepManagementModule, - PlatesModule, FanavaranLookupModule, LookupsModule, MulterModule.register({ diff --git a/test/contracts/api-routes.json b/test/contracts/api-routes.json index 6a9624a..53a97da 100644 --- a/test/contracts/api-routes.json +++ b/test/contracts/api-routes.json @@ -1,13 +1,4 @@ [ - { - "controller": "ProfileController", - "method": "DELETE", - "path": "/user/profile/plate/:id", - "guards": [ - "GlobalGuard" - ], - "roles": [] - }, { "controller": "WorkflowStepManagementController", "method": "DELETE", @@ -2612,15 +2603,6 @@ ], "roles": [] }, - { - "controller": "ProfileController", - "method": "POST", - "path": "/user/profile/plate", - "guards": [ - "GlobalGuard" - ], - "roles": [] - }, { "controller": "UserAuthController", "method": "POST",