Remove profile plate management and restrict personal profile updates

This commit is contained in:
SepehrYahyaee
2026-10-07 12:51:44 +03:30
parent 431bdea472
commit 073dd9792f
16 changed files with 76 additions and 210 deletions
+12
View File
@@ -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.
-2
View File
@@ -16,7 +16,6 @@ import { ExpertClaimModule } from "./expert-claim/expert-claim.module";
import { ExpertInsurerModule } from "./expert-insurer/expert-insurer.module"; import { ExpertInsurerModule } from "./expert-insurer/expert-insurer.module";
import { CaseExpertReportModule } from "./case-expert-report/case-expert-report.module"; import { CaseExpertReportModule } from "./case-expert-report/case-expert-report.module";
import { LookupsModule } from "./lookups/lookups.module"; import { LookupsModule } from "./lookups/lookups.module";
import { PlatesModule } from "./plates/plates.module";
import { ProfileModule } from "./profile/profile.module"; import { ProfileModule } from "./profile/profile.module";
import { SandHubModule } from "./sand-hub/sand-hub.module"; import { SandHubModule } from "./sand-hub/sand-hub.module";
import { SystemSettingsModule } from "./system-settings/system-settings.module"; import { SystemSettingsModule } from "./system-settings/system-settings.module";
@@ -54,7 +53,6 @@ import { PriceEstimationModule } from "./price-estimation/price-estimation.modul
AuthModule, AuthModule,
ClientModule, ClientModule,
ProfileModule, ProfileModule,
PlatesModule,
RequestManagementModule, RequestManagementModule,
SandHubModule, SandHubModule,
SystemSettingsModule, SystemSettingsModule,
-2
View File
@@ -1,6 +1,5 @@
import { Module } from "@nestjs/common"; import { Module } from "@nestjs/common";
import { ClientModule } from "src/client/client.module"; import { ClientModule } from "src/client/client.module";
import { PlatesModule } from "src/plates/plates.module";
import { UsersModule } from "src/users/users.module"; import { UsersModule } from "src/users/users.module";
import { ExpertBlameController } from "./expert-blame.controller"; import { ExpertBlameController } from "./expert-blame.controller";
import { ExpertBlameV2Controller } from "./expert-blame.v2.controller"; import { ExpertBlameV2Controller } from "./expert-blame.v2.controller";
@@ -15,7 +14,6 @@ import { ClaimRequestManagementModule } from "src/claim-request-management/claim
UsersModule, UsersModule,
ClientModule, ClientModule,
RequestManagementModule, RequestManagementModule,
PlatesModule,
SmsOrchestrationModule, SmsOrchestrationModule,
ClaimRequestManagementModule, ClaimRequestManagementModule,
LookupsModule, LookupsModule,
@@ -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<PlatesModel>,
) {}
async create(plate: PlatesModel): Promise<PlatesModel> {
return await this.plateModel.create(plate);
}
async findOne(plate: PlatesModel): Promise<PlatesModel> {
return await this.plateModel.findOne(plate);
}
async findAndRemove(id: Types.ObjectId): Promise<PlatesModel> {
return await this.plateModel.findOneAndUpdate(
{ _id: id },
{ isDelete: true },
{ upsert: true },
);
}
}
-24
View File
@@ -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);
-24
View File
@@ -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 {}
-55
View File
@@ -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" };
}
}
-13
View File
@@ -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"; import { InquiryParticipantFieldsDto } from "src/common/dto/inquiry-participants.dto";
export class AddPlateDto extends InquiryParticipantFieldsDto {} export class AddPlateDto extends InquiryParticipantFieldsDto {}
export class AddPlateProfileDto {
plateId: string;
@ApiProperty({ type: PlatesDto, required: true })
plate: Plates;
@ApiProperty({ type: String, required: true })
nationalCodeOfInsurer: string;
}
+7 -6
View File
@@ -6,20 +6,21 @@ export class ProfileUserRq {
id: string; id: string;
} }
export class ProfileUserRs extends UserModel { export class ProfileUserRs {
userId: string; userId: string;
fullName: string; fullName: string;
constructor(profile: UserModel, carDetail) { mobile: string;
super(); nationalCode: string;
birthDay: string;
gender?: "male" | "female";
city: string;
constructor(profile: UserModel) {
this.userId = profile["_id"]; this.userId = profile["_id"];
this.fullName = profile.fullName; this.fullName = profile.fullName;
this.mobile = profile.mobile; this.mobile = profile.mobile;
this.plates = profile.plates || null;
this.nationalCode = profile.nationalCode; this.nationalCode = profile.nationalCode;
this.birthDay = profile.birthDay; this.birthDay = profile.birthDay;
this.gender = profile.gender; this.gender = profile.gender;
this.plates = profile.plates;
this.city = profile.city; this.city = profile.city;
// this.carDetail
} }
} }
-2
View File
@@ -1,7 +1,6 @@
import { Test, TestingModule } from "@nestjs/testing"; import { Test, TestingModule } from "@nestjs/testing";
import { ProfileController } from "./profile.controller"; import { ProfileController } from "./profile.controller";
import { ProfileService } from "./profile.service"; import { ProfileService } from "./profile.service";
import { PlatesService } from "src/plates/plates.service";
import { JwtService } from "@nestjs/jwt"; import { JwtService } from "@nestjs/jwt";
describe("ProfileController", () => { describe("ProfileController", () => {
@@ -12,7 +11,6 @@ describe("ProfileController", () => {
controllers: [ProfileController], controllers: [ProfileController],
providers: [ providers: [
{ provide: ProfileService, useValue: {} }, { provide: ProfileService, useValue: {} },
{ provide: PlatesService, useValue: {} },
{ provide: JwtService, useValue: {} }, { provide: JwtService, useValue: {} },
], ],
}).compile(); }).compile();
+3 -31
View File
@@ -1,19 +1,8 @@
import { import { Controller, Get, Body, Patch, UseGuards } from "@nestjs/common";
Controller, import { ApiBearerAuth, ApiBody, ApiTags } from "@nestjs/swagger";
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 { GlobalGuard } from "src/auth/guards/global.guard";
import { CurrentUser } from "src/decorators/user.decorator"; import { CurrentUser } from "src/decorators/user.decorator";
import { Roles } from "src/decorators/roles.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 { UpdateUserProfileDtoRq } from "./dto/user/update-profile.dto";
import { ProfileService } from "./profile.service"; import { ProfileService } from "./profile.service";
@@ -22,10 +11,7 @@ import { ProfileService } from "./profile.service";
@ApiBearerAuth() @ApiBearerAuth()
@Roles() @Roles()
export class ProfileController { export class ProfileController {
constructor( constructor(private readonly profileService: ProfileService) {}
private readonly profileService: ProfileService,
private readonly plateService: PlatesService,
) {}
@Get() @Get()
@UseGuards(GlobalGuard) @UseGuards(GlobalGuard)
@@ -42,18 +28,4 @@ export class ProfileController {
) { ) {
return await this.profileService.updateProfile(user.username, body); 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);
}
} }
+1 -2
View File
@@ -1,11 +1,10 @@
import { Module } from "@nestjs/common"; import { Module } from "@nestjs/common";
import { PlatesModule } from "src/plates/plates.module";
import { UsersModule } from "src/users/users.module"; import { UsersModule } from "src/users/users.module";
import { ProfileController } from "./profile.controller"; import { ProfileController } from "./profile.controller";
import { ProfileService } from "./profile.service"; import { ProfileService } from "./profile.service";
@Module({ @Module({
imports: [UsersModule, PlatesModule], imports: [UsersModule],
controllers: [ProfileController], controllers: [ProfileController],
providers: [ProfileService], providers: [ProfileService],
}) })
+42
View File
@@ -4,6 +4,7 @@ import { UserDbService } from "src/users/entities/db-service/user.db.service";
describe("ProfileService", () => { describe("ProfileService", () => {
let service: ProfileService; let service: ProfileService;
let users: { findOne: jest.Mock; findOneAndUpdate: jest.Mock };
beforeEach(async () => { beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({ const module: TestingModule = await Test.createTestingModule({
@@ -20,9 +21,50 @@ describe("ProfileService", () => {
}).compile(); }).compile();
service = module.get<ProfileService>(ProfileService); service = module.get<ProfileService>(ProfileService);
users = module.get(UserDbService);
}); });
it("should be defined", () => { it("should be defined", () => {
expect(service).toBeDefined(); 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");
});
}); });
+11 -3
View File
@@ -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 { UserDbService } from "src/users/entities/db-service/user.db.service";
import { ProfileUserRs } from "./dto/user/profile.dto"; import { ProfileUserRs } from "./dto/user/profile.dto";
@@ -8,10 +8,18 @@ export class ProfileService {
async getProfileDetail(username: string) { async getProfileDetail(username: string) {
const userDetail = await this.userDbService.findOne({ username }); const userDetail = await this.userDbService.findOne({ username });
return new ProfileUserRs(userDetail, {}); return new ProfileUserRs(userDetail);
} }
async updateProfile(username: string, update) { 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);
} }
} }
@@ -3,7 +3,6 @@ import { MongooseModule } from "@nestjs/mongoose";
import { MulterModule } from "@nestjs/platform-express"; import { MulterModule } from "@nestjs/platform-express";
import { ClaimRequestManagementModule } from "src/claim-request-management/claim-request-management.module"; import { ClaimRequestManagementModule } from "src/claim-request-management/claim-request-management.module";
import { ClientModule } from "src/client/client.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 { 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 { 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"; 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, HashModule,
PlateNormalizerModule, PlateNormalizerModule,
WorkflowStepManagementModule, WorkflowStepManagementModule,
PlatesModule,
FanavaranLookupModule, FanavaranLookupModule,
LookupsModule, LookupsModule,
MulterModule.register({ MulterModule.register({
-18
View File
@@ -1,13 +1,4 @@
[ [
{
"controller": "ProfileController",
"method": "DELETE",
"path": "/user/profile/plate/:id",
"guards": [
"GlobalGuard"
],
"roles": []
},
{ {
"controller": "WorkflowStepManagementController", "controller": "WorkflowStepManagementController",
"method": "DELETE", "method": "DELETE",
@@ -2612,15 +2603,6 @@
], ],
"roles": [] "roles": []
}, },
{
"controller": "ProfileController",
"method": "POST",
"path": "/user/profile/plate",
"guards": [
"GlobalGuard"
],
"roles": []
},
{ {
"controller": "UserAuthController", "controller": "UserAuthController",
"method": "POST", "method": "POST",