reserves module

This commit is contained in:
2026-06-29 08:39:34 +03:30
parent 127c1eaf78
commit d8086cab17
15 changed files with 871 additions and 0 deletions
@@ -0,0 +1,183 @@
import {
MigrationInterface,
QueryRunner,
Table,
TableForeignKey,
TableIndex,
} from 'typeorm';
export class AddReserves1719900000000 implements MigrationInterface {
name = 'AddReserves1719900000000';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
CREATE TYPE "reserves_status_enum" AS ENUM(
'pending',
'confirmed',
'completed',
'cancelled',
'no_show'
)
`);
await queryRunner.createTable(
new Table({
name: 'reserves',
columns: [
{
name: 'id',
type: 'uuid',
isPrimary: true,
generationStrategy: 'uuid',
default: 'gen_random_uuid()',
},
{ name: 'salonId', type: 'uuid' },
{ name: 'customerId', type: 'uuid' },
{ name: 'stylistId', type: 'uuid' },
{ name: 'appointmentDate', type: 'date' },
{ name: 'startTime', type: 'time' },
{ name: 'endTime', type: 'time' },
{
name: 'status',
type: 'reserves_status_enum',
default: `'pending'`,
},
{ name: 'totalAmount', type: 'decimal', precision: 12, scale: 2 },
{ name: 'depositAmount', type: 'decimal', precision: 12, scale: 2 },
{ name: 'remainingAmount', type: 'decimal', precision: 12, scale: 2 },
{ name: 'cancellationReason', type: 'text', isNullable: true },
{ name: 'createdAt', type: 'timestamp', default: 'now()' },
{ name: 'updatedAt', type: 'timestamp', default: 'now()' },
],
}),
true,
);
await queryRunner.createTable(
new Table({
name: 'reserve_items',
columns: [
{
name: 'id',
type: 'uuid',
isPrimary: true,
generationStrategy: 'uuid',
default: 'gen_random_uuid()',
},
{ name: 'reserveId', type: 'uuid' },
{ name: 'serviceId', type: 'uuid' },
{ name: 'serviceSkillId', type: 'uuid' },
{ name: 'createdAt', type: 'timestamp', default: 'now()' },
{ name: 'updatedAt', type: 'timestamp', default: 'now()' },
],
}),
true,
);
await queryRunner.createForeignKey(
'reserves',
new TableForeignKey({
columnNames: ['salonId'],
referencedTableName: 'salons',
referencedColumnNames: ['id'],
onDelete: 'CASCADE',
}),
);
await queryRunner.createForeignKey(
'reserves',
new TableForeignKey({
columnNames: ['customerId'],
referencedTableName: 'customers',
referencedColumnNames: ['id'],
onDelete: 'CASCADE',
}),
);
await queryRunner.createForeignKey(
'reserves',
new TableForeignKey({
columnNames: ['stylistId'],
referencedTableName: 'stylists',
referencedColumnNames: ['id'],
onDelete: 'CASCADE',
}),
);
await queryRunner.createForeignKey(
'reserve_items',
new TableForeignKey({
columnNames: ['reserveId'],
referencedTableName: 'reserves',
referencedColumnNames: ['id'],
onDelete: 'CASCADE',
}),
);
await queryRunner.createForeignKey(
'reserve_items',
new TableForeignKey({
columnNames: ['serviceId'],
referencedTableName: 'services',
referencedColumnNames: ['id'],
onDelete: 'RESTRICT',
}),
);
await queryRunner.createForeignKey(
'reserve_items',
new TableForeignKey({
columnNames: ['serviceSkillId'],
referencedTableName: 'service_skills',
referencedColumnNames: ['id'],
onDelete: 'RESTRICT',
}),
);
await queryRunner.createIndex(
'reserves',
new TableIndex({
name: 'IDX_reserves_salonId_appointmentDate',
columnNames: ['salonId', 'appointmentDate'],
}),
);
await queryRunner.createIndex(
'reserves',
new TableIndex({
name: 'IDX_reserves_stylistId_appointmentDate',
columnNames: ['stylistId', 'appointmentDate'],
}),
);
await queryRunner.createIndex(
'reserves',
new TableIndex({
name: 'IDX_reserves_customerId',
columnNames: ['customerId'],
}),
);
await queryRunner.createIndex(
'reserves',
new TableIndex({
name: 'IDX_reserves_status',
columnNames: ['status'],
}),
);
await queryRunner.createIndex(
'reserve_items',
new TableIndex({
name: 'IDX_reserve_items_reserveId',
columnNames: ['reserveId'],
}),
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.dropTable('reserve_items', true);
await queryRunner.dropTable('reserves', true);
await queryRunner.query(`DROP TYPE "reserves_status_enum"`);
}
}