-
Notifications
You must be signed in to change notification settings - Fork 1
feat(customer): enforce unique phoneNumber with validation, duplicate handling & cleanup #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| # Changelog | ||
|
|
||
| All notable changes to this project will be documented in this file. | ||
| The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) | ||
| and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). | ||
|
|
||
| ## [Unreleased] | ||
| ### Added | ||
| - **Database**: Added a unique **and non-nullable** constraint on `phoneNumber` column of the `Customer` table (Prisma schema & migration). | ||
| - **API**: Implemented application-level handling for duplicate phone numbers – requests that attempt to create a customer with an existing `phoneNumber` now return **HTTP 409 Conflict** (error code `DuplicatePhoneNumberError`). | ||
| - **Validation**: `CustomerCreateInput` now validates that `phoneNumber` is non-empty and matches the expected numeric pattern. | ||
| - **Testing**: Added unit and integration tests covering duplicate phone number scenarios. | ||
|
|
||
| ### Changed | ||
| - Updated Swagger / DTO documentation to indicate that `phoneNumber` must be unique. | ||
|
|
||
| ### Fixed | ||
| - Prevented accidental creation of multiple customers with the same `phoneNumber`. | ||
|
|
||
| --- | ||
|
|
||
| ## [0.1.0] – 2025-09-11 | ||
| ### Added | ||
| - Initial public release generated by Amplication, containing server (NestJS GraphQL API) and admin UI (React-Admin). | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -180,6 +180,17 @@ Inside `apps/hotel-management-service-admin`: | |
|
|
||
| The Prisma schema is located under `apps/hotel-management-service-server/prisma/schema.prisma`. | ||
|
|
||
| > **Note**: Starting from the next release the `phoneNumber` field on the **Customer** model is now **required and unique** (non-nullable). Attempting to insert two customers with the same phone number – or omitting a phone number – will result in an HTTP 409 Conflict or 400 validation error respectively. | ||
| > | ||
| > Before you deploy this change to an existing database **you must clean up existing duplicates** (if any). A helper script is provided: | ||
| > | ||
| > ```bash | ||
| > cd apps/hotel-management-service-server | ||
| > npm run cleanup:duplicates # removes duplicates, keeping the earliest record per phone number | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @overcut i accept that , please add a commit with this change on this PR
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| > ``` | ||
| > | ||
| > Run the script once, verify the output, then proceed with the Prisma migration. | ||
|
|
||
| * Create & apply a new migration: | ||
|
|
||
| ```bash | ||
|
|
||

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor but important: the error class is named
DuplicatePhoneNumberErrorserver-side, but the client receives the standardized error codeDUPLICATE_PHONE_NUMBER. Aligning the wording here (or adding the literal string) makes it easier for frontend consumers scanning the changelog to know what to guard for.