Spaces:
Sleeping
Sleeping
fix: update branch menus
Browse files
backend/src/common/enums/MenuItemType.enum.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
export enum MenuItemType {
|
2 |
-
MON_CHINH = 1, // món chính
|
3 |
-
TRANG_MIENG = 2, // tráng miệng
|
4 |
-
GIAI_KHAT = 3, // giải khát
|
5 |
KHAC = 0, // khác
|
|
|
|
|
|
|
6 |
}
|
|
|
1 |
export enum MenuItemType {
|
|
|
|
|
|
|
2 |
KHAC = 0, // khác
|
3 |
+
MON_CHINH = 1, // món chính
|
4 |
+
GIAI_KHAT = 2, // giải khát
|
5 |
+
TRANG_MIENG = 3, // tráng miệng
|
6 |
}
|
backend/src/entities/receipt.entity.ts
CHANGED
@@ -1,57 +1,57 @@
|
|
1 |
-
import {
|
2 |
-
BaseEntity,
|
3 |
-
Column,
|
4 |
-
CreateDateColumn,
|
5 |
-
Entity,
|
6 |
-
JoinColumn,
|
7 |
-
ManyToOne,
|
8 |
-
PrimaryGeneratedColumn,
|
9 |
-
Relation,
|
10 |
-
} from 'typeorm';
|
11 |
-
import { BranchEntity } from './branch.entity.js';
|
12 |
-
import { UserEntity } from './user.entity.js';
|
13 |
-
|
14 |
-
@Entity('receipts')
|
15 |
-
export class ReceiptEntity extends BaseEntity {
|
16 |
-
@PrimaryGeneratedColumn()
|
17 |
-
id: number;
|
18 |
-
|
19 |
-
@Column()
|
20 |
-
branch_id: string;
|
21 |
-
|
22 |
-
@ManyToOne(() => BranchEntity, (a) => a.receipts)
|
23 |
-
@JoinColumn({ name: 'branch_id' })
|
24 |
-
branch: Relation<BranchEntity>;
|
25 |
-
|
26 |
-
@Column({ default: 0 })
|
27 |
-
income: number;
|
28 |
-
|
29 |
-
@Column({ default: 0 })
|
30 |
-
spend: number;
|
31 |
-
|
32 |
-
@Column({ nullable: true })
|
33 |
-
description: string;
|
34 |
-
|
35 |
-
@Column({ default: 0 })
|
36 |
-
type: number;
|
37 |
-
|
38 |
-
@Column({ default: 0 })
|
39 |
-
sub_type: number;
|
40 |
-
|
41 |
-
@Column({ nullable: true })
|
42 |
-
sender_id: string;
|
43 |
-
|
44 |
-
@Column({ nullable: true })
|
45 |
-
receiver_id: string;
|
46 |
-
|
47 |
-
@ManyToOne(() => UserEntity, (a) => a.out_receipts)
|
48 |
-
@JoinColumn({ name: 'sender_id' })
|
49 |
-
sender: Relation<UserEntity>;
|
50 |
-
|
51 |
-
@ManyToOne(() => UserEntity, (a) => a.in_receipts)
|
52 |
-
@JoinColumn({ name: 'receiver_id' })
|
53 |
-
receiver: Relation<UserEntity>;
|
54 |
-
|
55 |
-
@CreateDateColumn()
|
56 |
-
created_at: Date;
|
57 |
-
}
|
|
|
1 |
+
import {
|
2 |
+
BaseEntity,
|
3 |
+
Column,
|
4 |
+
CreateDateColumn,
|
5 |
+
Entity,
|
6 |
+
JoinColumn,
|
7 |
+
ManyToOne,
|
8 |
+
PrimaryGeneratedColumn,
|
9 |
+
Relation,
|
10 |
+
} from 'typeorm';
|
11 |
+
import { BranchEntity } from './branch.entity.js';
|
12 |
+
import { UserEntity } from './user.entity.js';
|
13 |
+
|
14 |
+
@Entity('receipts')
|
15 |
+
export class ReceiptEntity extends BaseEntity {
|
16 |
+
@PrimaryGeneratedColumn()
|
17 |
+
id: number;
|
18 |
+
|
19 |
+
@Column()
|
20 |
+
branch_id: string;
|
21 |
+
|
22 |
+
@ManyToOne(() => BranchEntity, (a) => a.receipts)
|
23 |
+
@JoinColumn({ name: 'branch_id' })
|
24 |
+
branch: Relation<BranchEntity>;
|
25 |
+
|
26 |
+
@Column({ default: 0 })
|
27 |
+
income: number;
|
28 |
+
|
29 |
+
@Column({ default: 0 })
|
30 |
+
spend: number;
|
31 |
+
|
32 |
+
@Column({ nullable: true })
|
33 |
+
description: string;
|
34 |
+
|
35 |
+
@Column({ default: 0 })
|
36 |
+
type: number;
|
37 |
+
|
38 |
+
@Column({ default: 0 })
|
39 |
+
sub_type: number;
|
40 |
+
|
41 |
+
@Column({ nullable: true })
|
42 |
+
sender_id: string;
|
43 |
+
|
44 |
+
@Column({ nullable: true })
|
45 |
+
receiver_id: string;
|
46 |
+
|
47 |
+
@ManyToOne(() => UserEntity, (a) => a.out_receipts)
|
48 |
+
@JoinColumn({ name: 'sender_id' })
|
49 |
+
sender: Relation<UserEntity>;
|
50 |
+
|
51 |
+
@ManyToOne(() => UserEntity, (a) => a.in_receipts)
|
52 |
+
@JoinColumn({ name: 'receiver_id' })
|
53 |
+
receiver: Relation<UserEntity>;
|
54 |
+
|
55 |
+
@CreateDateColumn()
|
56 |
+
created_at: Date;
|
57 |
+
}
|
backend/src/migrations/1730547520878-AddReceipt.ts
CHANGED
@@ -1,30 +1,30 @@
|
|
1 |
-
import { MigrationInterface, QueryRunner } from "typeorm";
|
2 |
-
|
3 |
-
export class AddReceipt1730547520878 implements MigrationInterface {
|
4 |
-
name = 'AddReceipt1730547520878'
|
5 |
-
|
6 |
-
public async up(queryRunner: QueryRunner): Promise<void> {
|
7 |
-
await queryRunner.query(`CREATE TABLE "receipts" ("id" SERIAL NOT NULL, "branch_id" character varying NOT NULL, "income" integer NOT NULL DEFAULT '0', "spend" integer NOT NULL DEFAULT '0', "description" character varying, "type" integer NOT NULL DEFAULT '0', "sub_type" integer NOT NULL DEFAULT '0', "sender_id" uuid, "receiver_id" uuid, "created_at" TIMESTAMP NOT NULL DEFAULT now(), CONSTRAINT "PK_5e8182d7c29e023da6e1ff33bfe" PRIMARY KEY ("id"))`);
|
8 |
-
await queryRunner.query(`ALTER TABLE "branches" ADD "image_url" character varying`);
|
9 |
-
await queryRunner.query(`ALTER TABLE "branch_menu" ADD "sold_count" integer NOT NULL DEFAULT '0'`);
|
10 |
-
await queryRunner.query(`ALTER TABLE "branches" ALTER COLUMN "name" DROP NOT NULL`);
|
11 |
-
await queryRunner.query(`ALTER TABLE "branches" ALTER COLUMN "location" DROP NOT NULL`);
|
12 |
-
await queryRunner.query(`ALTER TABLE "branches" ALTER COLUMN "phone_number" DROP NOT NULL`);
|
13 |
-
await queryRunner.query(`ALTER TABLE "receipts" ADD CONSTRAINT "FK_82e9dee911c0e7393154d1d98ad" FOREIGN KEY ("branch_id") REFERENCES "branches"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
|
14 |
-
await queryRunner.query(`ALTER TABLE "receipts" ADD CONSTRAINT "FK_eda4c4e486a25beef4dc82a41d5" FOREIGN KEY ("sender_id") REFERENCES "users"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
|
15 |
-
await queryRunner.query(`ALTER TABLE "receipts" ADD CONSTRAINT "FK_366c3d3cf125da97552f40001a1" FOREIGN KEY ("receiver_id") REFERENCES "users"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
|
16 |
-
}
|
17 |
-
|
18 |
-
public async down(queryRunner: QueryRunner): Promise<void> {
|
19 |
-
await queryRunner.query(`ALTER TABLE "receipts" DROP CONSTRAINT "FK_366c3d3cf125da97552f40001a1"`);
|
20 |
-
await queryRunner.query(`ALTER TABLE "receipts" DROP CONSTRAINT "FK_eda4c4e486a25beef4dc82a41d5"`);
|
21 |
-
await queryRunner.query(`ALTER TABLE "receipts" DROP CONSTRAINT "FK_82e9dee911c0e7393154d1d98ad"`);
|
22 |
-
await queryRunner.query(`ALTER TABLE "branches" ALTER COLUMN "phone_number" SET NOT NULL`);
|
23 |
-
await queryRunner.query(`ALTER TABLE "branches" ALTER COLUMN "location" SET NOT NULL`);
|
24 |
-
await queryRunner.query(`ALTER TABLE "branches" ALTER COLUMN "name" SET NOT NULL`);
|
25 |
-
await queryRunner.query(`ALTER TABLE "branch_menu" DROP COLUMN "sold_count"`);
|
26 |
-
await queryRunner.query(`ALTER TABLE "branches" DROP COLUMN "image_url"`);
|
27 |
-
await queryRunner.query(`DROP TABLE "receipts"`);
|
28 |
-
}
|
29 |
-
|
30 |
-
}
|
|
|
1 |
+
import { MigrationInterface, QueryRunner } from "typeorm";
|
2 |
+
|
3 |
+
export class AddReceipt1730547520878 implements MigrationInterface {
|
4 |
+
name = 'AddReceipt1730547520878'
|
5 |
+
|
6 |
+
public async up(queryRunner: QueryRunner): Promise<void> {
|
7 |
+
await queryRunner.query(`CREATE TABLE "receipts" ("id" SERIAL NOT NULL, "branch_id" character varying NOT NULL, "income" integer NOT NULL DEFAULT '0', "spend" integer NOT NULL DEFAULT '0', "description" character varying, "type" integer NOT NULL DEFAULT '0', "sub_type" integer NOT NULL DEFAULT '0', "sender_id" uuid, "receiver_id" uuid, "created_at" TIMESTAMP NOT NULL DEFAULT now(), CONSTRAINT "PK_5e8182d7c29e023da6e1ff33bfe" PRIMARY KEY ("id"))`);
|
8 |
+
await queryRunner.query(`ALTER TABLE "branches" ADD "image_url" character varying`);
|
9 |
+
await queryRunner.query(`ALTER TABLE "branch_menu" ADD "sold_count" integer NOT NULL DEFAULT '0'`);
|
10 |
+
await queryRunner.query(`ALTER TABLE "branches" ALTER COLUMN "name" DROP NOT NULL`);
|
11 |
+
await queryRunner.query(`ALTER TABLE "branches" ALTER COLUMN "location" DROP NOT NULL`);
|
12 |
+
await queryRunner.query(`ALTER TABLE "branches" ALTER COLUMN "phone_number" DROP NOT NULL`);
|
13 |
+
await queryRunner.query(`ALTER TABLE "receipts" ADD CONSTRAINT "FK_82e9dee911c0e7393154d1d98ad" FOREIGN KEY ("branch_id") REFERENCES "branches"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
|
14 |
+
await queryRunner.query(`ALTER TABLE "receipts" ADD CONSTRAINT "FK_eda4c4e486a25beef4dc82a41d5" FOREIGN KEY ("sender_id") REFERENCES "users"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
|
15 |
+
await queryRunner.query(`ALTER TABLE "receipts" ADD CONSTRAINT "FK_366c3d3cf125da97552f40001a1" FOREIGN KEY ("receiver_id") REFERENCES "users"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
|
16 |
+
}
|
17 |
+
|
18 |
+
public async down(queryRunner: QueryRunner): Promise<void> {
|
19 |
+
await queryRunner.query(`ALTER TABLE "receipts" DROP CONSTRAINT "FK_366c3d3cf125da97552f40001a1"`);
|
20 |
+
await queryRunner.query(`ALTER TABLE "receipts" DROP CONSTRAINT "FK_eda4c4e486a25beef4dc82a41d5"`);
|
21 |
+
await queryRunner.query(`ALTER TABLE "receipts" DROP CONSTRAINT "FK_82e9dee911c0e7393154d1d98ad"`);
|
22 |
+
await queryRunner.query(`ALTER TABLE "branches" ALTER COLUMN "phone_number" SET NOT NULL`);
|
23 |
+
await queryRunner.query(`ALTER TABLE "branches" ALTER COLUMN "location" SET NOT NULL`);
|
24 |
+
await queryRunner.query(`ALTER TABLE "branches" ALTER COLUMN "name" SET NOT NULL`);
|
25 |
+
await queryRunner.query(`ALTER TABLE "branch_menu" DROP COLUMN "sold_count"`);
|
26 |
+
await queryRunner.query(`ALTER TABLE "branches" DROP COLUMN "image_url"`);
|
27 |
+
await queryRunner.query(`DROP TABLE "receipts"`);
|
28 |
+
}
|
29 |
+
|
30 |
+
}
|
backend/src/migrations/1730549959767-RemoveEnums.ts
CHANGED
@@ -1,36 +1,36 @@
|
|
1 |
-
import { MigrationInterface, QueryRunner } from "typeorm";
|
2 |
-
|
3 |
-
export class RemoveEnums1730549959767 implements MigrationInterface {
|
4 |
-
name = 'RemoveEnums1730549959767'
|
5 |
-
|
6 |
-
public async up(queryRunner: QueryRunner): Promise<void> {
|
7 |
-
await queryRunner.query(`ALTER TABLE "menu_items" DROP COLUMN "item_type"`);
|
8 |
-
await queryRunner.query(`DROP TYPE "public"."menu_items_item_type_enum"`);
|
9 |
-
await queryRunner.query(`ALTER TABLE "menu_items" ADD "item_type" integer NOT NULL DEFAULT '0'`);
|
10 |
-
await queryRunner.query(`ALTER TABLE "payments" DROP COLUMN "payment_method"`);
|
11 |
-
await queryRunner.query(`DROP TYPE "public"."payments_payment_method_enum"`);
|
12 |
-
await queryRunner.query(`ALTER TABLE "payments" ADD "payment_method" integer NOT NULL DEFAULT '0'`);
|
13 |
-
await queryRunner.query(`ALTER TABLE "orders" DROP COLUMN "order_type"`);
|
14 |
-
await queryRunner.query(`DROP TYPE "public"."orders_order_type_enum"`);
|
15 |
-
await queryRunner.query(`ALTER TABLE "orders" ADD "order_type" integer NOT NULL DEFAULT '0'`);
|
16 |
-
await queryRunner.query(`ALTER TABLE "orders" DROP COLUMN "order_status"`);
|
17 |
-
await queryRunner.query(`DROP TYPE "public"."orders_order_status_enum"`);
|
18 |
-
await queryRunner.query(`ALTER TABLE "orders" ADD "order_status" integer NOT NULL DEFAULT '0'`);
|
19 |
-
}
|
20 |
-
|
21 |
-
public async down(queryRunner: QueryRunner): Promise<void> {
|
22 |
-
await queryRunner.query(`ALTER TABLE "orders" DROP COLUMN "order_status"`);
|
23 |
-
await queryRunner.query(`CREATE TYPE "public"."orders_order_status_enum" AS ENUM('pending', 'confirmed', 'preparing', 'delivering', 'done')`);
|
24 |
-
await queryRunner.query(`ALTER TABLE "orders" ADD "order_status" "public"."orders_order_status_enum" NOT NULL DEFAULT 'pending'`);
|
25 |
-
await queryRunner.query(`ALTER TABLE "orders" DROP COLUMN "order_type"`);
|
26 |
-
await queryRunner.query(`CREATE TYPE "public"."orders_order_type_enum" AS ENUM('take_away', 'offline', 'online')`);
|
27 |
-
await queryRunner.query(`ALTER TABLE "orders" ADD "order_type" "public"."orders_order_type_enum" NOT NULL DEFAULT 'online'`);
|
28 |
-
await queryRunner.query(`ALTER TABLE "payments" DROP COLUMN "payment_method"`);
|
29 |
-
await queryRunner.query(`CREATE TYPE "public"."payments_payment_method_enum" AS ENUM('cash', 'card', 'online_payment')`);
|
30 |
-
await queryRunner.query(`ALTER TABLE "payments" ADD "payment_method" "public"."payments_payment_method_enum" NOT NULL DEFAULT 'cash'`);
|
31 |
-
await queryRunner.query(`ALTER TABLE "menu_items" DROP COLUMN "item_type"`);
|
32 |
-
await queryRunner.query(`CREATE TYPE "public"."menu_items_item_type_enum" AS ENUM('monchinh', 'trangmieng', 'giaikhat', 'khac')`);
|
33 |
-
await queryRunner.query(`ALTER TABLE "menu_items" ADD "item_type" "public"."menu_items_item_type_enum" NOT NULL DEFAULT 'khac'`);
|
34 |
-
}
|
35 |
-
|
36 |
-
}
|
|
|
1 |
+
import { MigrationInterface, QueryRunner } from "typeorm";
|
2 |
+
|
3 |
+
export class RemoveEnums1730549959767 implements MigrationInterface {
|
4 |
+
name = 'RemoveEnums1730549959767'
|
5 |
+
|
6 |
+
public async up(queryRunner: QueryRunner): Promise<void> {
|
7 |
+
await queryRunner.query(`ALTER TABLE "menu_items" DROP COLUMN "item_type"`);
|
8 |
+
await queryRunner.query(`DROP TYPE "public"."menu_items_item_type_enum"`);
|
9 |
+
await queryRunner.query(`ALTER TABLE "menu_items" ADD "item_type" integer NOT NULL DEFAULT '0'`);
|
10 |
+
await queryRunner.query(`ALTER TABLE "payments" DROP COLUMN "payment_method"`);
|
11 |
+
await queryRunner.query(`DROP TYPE "public"."payments_payment_method_enum"`);
|
12 |
+
await queryRunner.query(`ALTER TABLE "payments" ADD "payment_method" integer NOT NULL DEFAULT '0'`);
|
13 |
+
await queryRunner.query(`ALTER TABLE "orders" DROP COLUMN "order_type"`);
|
14 |
+
await queryRunner.query(`DROP TYPE "public"."orders_order_type_enum"`);
|
15 |
+
await queryRunner.query(`ALTER TABLE "orders" ADD "order_type" integer NOT NULL DEFAULT '0'`);
|
16 |
+
await queryRunner.query(`ALTER TABLE "orders" DROP COLUMN "order_status"`);
|
17 |
+
await queryRunner.query(`DROP TYPE "public"."orders_order_status_enum"`);
|
18 |
+
await queryRunner.query(`ALTER TABLE "orders" ADD "order_status" integer NOT NULL DEFAULT '0'`);
|
19 |
+
}
|
20 |
+
|
21 |
+
public async down(queryRunner: QueryRunner): Promise<void> {
|
22 |
+
await queryRunner.query(`ALTER TABLE "orders" DROP COLUMN "order_status"`);
|
23 |
+
await queryRunner.query(`CREATE TYPE "public"."orders_order_status_enum" AS ENUM('pending', 'confirmed', 'preparing', 'delivering', 'done')`);
|
24 |
+
await queryRunner.query(`ALTER TABLE "orders" ADD "order_status" "public"."orders_order_status_enum" NOT NULL DEFAULT 'pending'`);
|
25 |
+
await queryRunner.query(`ALTER TABLE "orders" DROP COLUMN "order_type"`);
|
26 |
+
await queryRunner.query(`CREATE TYPE "public"."orders_order_type_enum" AS ENUM('take_away', 'offline', 'online')`);
|
27 |
+
await queryRunner.query(`ALTER TABLE "orders" ADD "order_type" "public"."orders_order_type_enum" NOT NULL DEFAULT 'online'`);
|
28 |
+
await queryRunner.query(`ALTER TABLE "payments" DROP COLUMN "payment_method"`);
|
29 |
+
await queryRunner.query(`CREATE TYPE "public"."payments_payment_method_enum" AS ENUM('cash', 'card', 'online_payment')`);
|
30 |
+
await queryRunner.query(`ALTER TABLE "payments" ADD "payment_method" "public"."payments_payment_method_enum" NOT NULL DEFAULT 'cash'`);
|
31 |
+
await queryRunner.query(`ALTER TABLE "menu_items" DROP COLUMN "item_type"`);
|
32 |
+
await queryRunner.query(`CREATE TYPE "public"."menu_items_item_type_enum" AS ENUM('monchinh', 'trangmieng', 'giaikhat', 'khac')`);
|
33 |
+
await queryRunner.query(`ALTER TABLE "menu_items" ADD "item_type" "public"."menu_items_item_type_enum" NOT NULL DEFAULT 'khac'`);
|
34 |
+
}
|
35 |
+
|
36 |
+
}
|
backend/src/modules/branch-menus/branch-menus.service.ts
CHANGED
@@ -4,7 +4,12 @@ import { UpdateBranchMenuDto } from './dto/update-branch-menu.dto.js';
|
|
4 |
import { BranchService } from '../branch/branch.service.js';
|
5 |
import { MenuItemService } from '../menu-item/menu-item.service.js';
|
6 |
import { BranchMenuEntity } from '../../entities/branch-menu.entity.js';
|
7 |
-
import {
|
|
|
|
|
|
|
|
|
|
|
8 |
import { isUUID } from 'class-validator';
|
9 |
|
10 |
@Injectable()
|
@@ -36,12 +41,18 @@ export class BranchMenusService {
|
|
36 |
const paginateConfig: PaginateConfig<BranchMenuEntity> = {
|
37 |
sortableColumns: ['id', 'branch_id', 'menu_id', 'description'],
|
38 |
nullSort: 'last',
|
39 |
-
defaultSortBy: [['
|
40 |
searchableColumns: ['description'],
|
41 |
filterableColumns: {
|
42 |
-
|
43 |
-
|
|
|
|
|
|
|
|
|
|
|
44 |
},
|
|
|
45 |
};
|
46 |
return paginate(
|
47 |
query,
|
|
|
4 |
import { BranchService } from '../branch/branch.service.js';
|
5 |
import { MenuItemService } from '../menu-item/menu-item.service.js';
|
6 |
import { BranchMenuEntity } from '../../entities/branch-menu.entity.js';
|
7 |
+
import {
|
8 |
+
FilterOperator,
|
9 |
+
paginate,
|
10 |
+
PaginateConfig,
|
11 |
+
PaginateQuery,
|
12 |
+
} from 'nestjs-paginate';
|
13 |
import { isUUID } from 'class-validator';
|
14 |
|
15 |
@Injectable()
|
|
|
41 |
const paginateConfig: PaginateConfig<BranchMenuEntity> = {
|
42 |
sortableColumns: ['id', 'branch_id', 'menu_id', 'description'],
|
43 |
nullSort: 'last',
|
44 |
+
defaultSortBy: [['menu_item.item_type', 'ASC']],
|
45 |
searchableColumns: ['description'],
|
46 |
filterableColumns: {
|
47 |
+
'menu_item.price': [
|
48 |
+
FilterOperator.LT,
|
49 |
+
FilterOperator.LTE,
|
50 |
+
FilterOperator.GT,
|
51 |
+
FilterOperator.GTE,
|
52 |
+
],
|
53 |
+
'menu_item.item_type': [FilterOperator.EQ, FilterOperator.IN],
|
54 |
},
|
55 |
+
relations: ['menu_item'],
|
56 |
};
|
57 |
return paginate(
|
58 |
query,
|