-
Notifications
You must be signed in to change notification settings - Fork 0
feat(cancelled-bookings): implement cancelled bookings functionality … #56
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| import { | ||
| Column, | ||
| CreateDateColumn, | ||
| Entity, | ||
| JoinColumn, | ||
| ManyToOne, | ||
| PrimaryGeneratedColumn, | ||
| } from "typeorm"; | ||
| import { UserAccount } from "../../auth/entities/user.entity"; | ||
| import { Field } from "../../fields/entities/field.entity"; | ||
| import { FieldSlot } from "../../fields/entities/field-slot.entity"; | ||
|
|
||
| @Entity({ name: "cancelled_bookings" }) | ||
| export class CancelledBooking { | ||
| @PrimaryGeneratedColumn("uuid") | ||
| id!: string; | ||
|
|
||
| @Column({ name: "original_booking_id", type: "uuid", nullable: true }) | ||
| originalBookingId?: string; | ||
|
|
||
| @Column({ name: "field_id", type: "uuid" }) | ||
| fieldId!: string; | ||
|
|
||
| @ManyToOne(() => Field, { onDelete: "CASCADE" }) | ||
| @JoinColumn({ name: "field_id" }) | ||
| field!: Field; | ||
|
|
||
| @Column({ name: "slot_id", type: "uuid" }) | ||
| slotId!: string; | ||
|
|
||
| @ManyToOne(() => FieldSlot, { onDelete: "CASCADE" }) | ||
| @JoinColumn({ name: "slot_id" }) | ||
| slot!: FieldSlot; | ||
|
|
||
| @Column({ name: "user_id", type: "uuid" }) | ||
| userId!: string; | ||
|
|
||
| @ManyToOne(() => UserAccount, { onDelete: "CASCADE" }) | ||
| @JoinColumn({ name: "user_id" }) | ||
| user!: UserAccount; | ||
|
|
||
| @Column({ name: "booking_type", type: "varchar", nullable: true }) | ||
| bookingType?: string; | ||
|
|
||
| @Column({ | ||
| name: "base_amount", | ||
| type: "numeric", | ||
| precision: 12, | ||
| scale: 2, | ||
| default: 0, | ||
| }) | ||
| baseAmount!: string; | ||
|
|
||
| @Column({ | ||
| name: "total_amount", | ||
| type: "numeric", | ||
| precision: 12, | ||
| scale: 2, | ||
| default: 0, | ||
| }) | ||
| totalAmount!: string; | ||
|
|
||
| @Column({ name: "discount", type: "boolean", default: false }) | ||
| discount!: boolean; | ||
|
|
||
| @Column({ | ||
| name: "extra_amount", | ||
| type: "numeric", | ||
| precision: 12, | ||
| scale: 2, | ||
| default: 0, | ||
| }) | ||
| extraAmount!: string; | ||
|
|
||
| @Column({ | ||
| name: "discount_amount", | ||
| type: "numeric", | ||
| precision: 12, | ||
| scale: 2, | ||
| default: 0, | ||
| }) | ||
| discountAmount!: string; | ||
|
|
||
| @CreateDateColumn({ name: "created_at" }) | ||
| createdAt!: Date; | ||
|
AyushAdh1 marked this conversation as resolved.
Outdated
|
||
|
|
||
| @Column({ name: "cancelled_at", type: "timestamptz", default: () => "now()" }) | ||
| cancelledAt!: Date; | ||
|
|
||
| @Column({ name: "cancelled_by", type: "uuid", nullable: true }) | ||
| cancelledBy?: string; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/migrations/1780001000000-MakeBookingsSlotIdPartialUnique.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import { MigrationInterface, QueryRunner } from "typeorm"; | ||
|
|
||
| export class MakeBookingsSlotIdPartialUnique1780001000000 implements MigrationInterface { | ||
| public async up(queryRunner: QueryRunner): Promise<void> { | ||
| // Remove any existing unique constraint/index on slot_id so we can create | ||
| // a partial unique index that ignores cancelled bookings. | ||
| await queryRunner.query( | ||
| `ALTER TABLE "bookings" DROP CONSTRAINT IF EXISTS "UQ_bookings_slot_id"`, | ||
| ); | ||
| await queryRunner.query(`DROP INDEX IF EXISTS "IDX_bookings_slot_id"`); | ||
| // Some older deployments may have generated a hashed index name; attempt to drop common variants. | ||
| await queryRunner.query( | ||
| `DROP INDEX IF EXISTS "IDX_409d5b76fb2b0501a8c72dd4ee"`, | ||
| ); | ||
|
|
||
| // Create a unique index for slot_id only when booking status is not 'cancelled'. | ||
| await queryRunner.query( | ||
| `CREATE UNIQUE INDEX IF NOT EXISTS "IDX_bookings_slot_id_active_unique" ON "bookings" ("slot_id") WHERE status <> 'cancelled'`, | ||
| ); | ||
| } | ||
|
|
||
| public async down(queryRunner: QueryRunner): Promise<void> { | ||
| // Revert: drop the partial unique index and restore the original unique constraint | ||
| await queryRunner.query( | ||
| `DROP INDEX IF EXISTS "IDX_bookings_slot_id_active_unique"`, | ||
| ); | ||
| // Restore the original unique constraint on slot_id | ||
| await queryRunner.query( | ||
| `ALTER TABLE "bookings" ADD CONSTRAINT IF NOT EXISTS "UQ_bookings_slot_id" UNIQUE ("slot_id")`, | ||
| ); | ||
| } | ||
| } |
48 changes: 48 additions & 0 deletions
48
src/migrations/1780002000000-CreateCancelledBookingsTable.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| import { MigrationInterface, QueryRunner } from "typeorm"; | ||
|
|
||
| export class CreateCancelledBookingsTable1780002000000 implements MigrationInterface { | ||
| public async up(queryRunner: QueryRunner): Promise<void> { | ||
| await queryRunner.query(` | ||
| CREATE TABLE IF NOT EXISTS "cancelled_bookings" ( | ||
| "id" uuid NOT NULL DEFAULT uuid_generate_v4(), | ||
| "original_booking_id" uuid, | ||
| "field_id" uuid NOT NULL, | ||
| "slot_id" uuid NOT NULL, | ||
| "user_id" uuid NOT NULL, | ||
| "booking_type" varchar, | ||
| "base_amount" numeric(12,2) DEFAULT 0, | ||
| "total_amount" numeric(12,2) DEFAULT 0, | ||
| "discount" boolean DEFAULT false, | ||
| "extra_amount" numeric(12,2) DEFAULT 0, | ||
| "discount_amount" numeric(12,2) DEFAULT 0, | ||
| "created_at" TIMESTAMP NOT NULL DEFAULT now(), | ||
| "cancelled_at" timestamptz NOT NULL DEFAULT now(), | ||
| "cancelled_by" uuid, | ||
| CONSTRAINT "PK_cancelled_bookings_id" PRIMARY KEY ("id") | ||
| ) | ||
| `); | ||
|
AyushAdh1 marked this conversation as resolved.
|
||
|
|
||
| await queryRunner.query( | ||
| `CREATE INDEX IF NOT EXISTS "IDX_cancelled_bookings_field_id" ON "cancelled_bookings" ("field_id")`, | ||
| ); | ||
| await queryRunner.query( | ||
| `CREATE INDEX IF NOT EXISTS "IDX_cancelled_bookings_user_id" ON "cancelled_bookings" ("user_id")`, | ||
| ); | ||
| await queryRunner.query( | ||
| `CREATE INDEX IF NOT EXISTS "IDX_cancelled_bookings_slot_id" ON "cancelled_bookings" ("slot_id")`, | ||
| ); | ||
| } | ||
|
|
||
| public async down(queryRunner: QueryRunner): Promise<void> { | ||
| await queryRunner.query( | ||
| `DROP INDEX IF EXISTS "IDX_cancelled_bookings_slot_id"`, | ||
| ); | ||
| await queryRunner.query( | ||
| `DROP INDEX IF EXISTS "IDX_cancelled_bookings_user_id"`, | ||
| ); | ||
| await queryRunner.query( | ||
| `DROP INDEX IF EXISTS "IDX_cancelled_bookings_field_id"`, | ||
| ); | ||
| await queryRunner.query(`DROP TABLE IF EXISTS "cancelled_bookings"`); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.