Trần Viết Sơn commited on
Commit
f97bd0c
1 Parent(s): 6f39f03

add branch and branch menu

Browse files
backend/src/app.module.ts CHANGED
@@ -12,6 +12,8 @@ import { BranchModule } from './modules/branch/branch.module.js';
12
  import { AuthenticationModule } from './modules/authentication/authentication.module.js';
13
  import { MenuItemModule } from './modules/menu-item/menu-item.module.js';
14
  import { FeedsModule } from './modules/feeds/feeds.module.js';
 
 
15
  @Module({
16
  imports: [
17
  ConfigModule.forRoot({
@@ -27,6 +29,8 @@ import { FeedsModule } from './modules/feeds/feeds.module.js';
27
  AuthenticationModule,
28
  MenuItemModule,
29
  FeedsModule,
 
 
30
  ],
31
  controllers: [AppController],
32
  providers: [AppService],
 
12
  import { AuthenticationModule } from './modules/authentication/authentication.module.js';
13
  import { MenuItemModule } from './modules/menu-item/menu-item.module.js';
14
  import { FeedsModule } from './modules/feeds/feeds.module.js';
15
+ import { OrderModule } from './modules/order/order.module.js';
16
+ import { BranchMenusModule } from './modules/branch-menus/branch-menus.module.js';
17
  @Module({
18
  imports: [
19
  ConfigModule.forRoot({
 
29
  AuthenticationModule,
30
  MenuItemModule,
31
  FeedsModule,
32
+ OrderModule,
33
+ BranchMenusModule,
34
  ],
35
  controllers: [AppController],
36
  providers: [AppService],
backend/src/entities/branch-menu.entity.ts CHANGED
@@ -2,6 +2,7 @@ import {
2
  BaseEntity,
3
  Column,
4
  Entity,
 
5
  ManyToOne,
6
  OneToMany,
7
  PrimaryGeneratedColumn,
@@ -21,15 +22,17 @@ export class BranchMenuEntity extends BaseEntity {
21
  @Column()
22
  menu_id: string;
23
 
24
- @Column()
25
  description: string;
26
 
27
- @Column()
28
  is_open: boolean;
29
 
30
  @ManyToOne(() => BranchEntity, (a) => a.menu_items)
 
31
  branch: Relation<BranchEntity>;
32
 
33
  @ManyToOne(() => MenuItemEntity, (a) => a.branch_menus)
 
34
  menu_item: Relation<MenuItemEntity>;
35
  }
 
2
  BaseEntity,
3
  Column,
4
  Entity,
5
+ JoinColumn,
6
  ManyToOne,
7
  OneToMany,
8
  PrimaryGeneratedColumn,
 
22
  @Column()
23
  menu_id: string;
24
 
25
+ @Column({ nullable: true })
26
  description: string;
27
 
28
+ @Column({ default: true })
29
  is_open: boolean;
30
 
31
  @ManyToOne(() => BranchEntity, (a) => a.menu_items)
32
+ @JoinColumn({ name: 'branch_id' })
33
  branch: Relation<BranchEntity>;
34
 
35
  @ManyToOne(() => MenuItemEntity, (a) => a.branch_menus)
36
+ @JoinColumn({ name: 'menu_id' })
37
  menu_item: Relation<MenuItemEntity>;
38
  }
backend/src/entities/branch.entity.ts CHANGED
@@ -5,6 +5,7 @@ import {
5
  Entity,
6
  ManyToOne,
7
  OneToMany,
 
8
  PrimaryGeneratedColumn,
9
  Relation,
10
  } from 'typeorm';
@@ -13,7 +14,7 @@ import { BranchMenuEntity } from './branch-menu.entity.js';
13
 
14
  @Entity('branches')
15
  export class BranchEntity extends BaseEntity {
16
- @PrimaryGeneratedColumn('uuid')
17
  id: string;
18
 
19
  @Column()
 
5
  Entity,
6
  ManyToOne,
7
  OneToMany,
8
+ PrimaryColumn,
9
  PrimaryGeneratedColumn,
10
  Relation,
11
  } from 'typeorm';
 
14
 
15
  @Entity('branches')
16
  export class BranchEntity extends BaseEntity {
17
+ @PrimaryColumn()
18
  id: string;
19
 
20
  @Column()
backend/src/entities/order.entity.ts CHANGED
@@ -19,8 +19,8 @@ import { PaymentEntity } from './payment.entity.js';
19
 
20
  @Entity('orders')
21
  export class OrderEntity extends BaseEntity {
22
- @PrimaryGeneratedColumn('uuid')
23
- id: string;
24
 
25
  @Column({ nullable: true })
26
  customer_id: string;
 
19
 
20
  @Entity('orders')
21
  export class OrderEntity extends BaseEntity {
22
+ @PrimaryGeneratedColumn()
23
+ id: number;
24
 
25
  @Column({ nullable: true })
26
  customer_id: string;
backend/src/migrations/{1730397685489-RemoveAllAndAdd.ts → 1730432721785-RefactorAll.ts} RENAMED
@@ -1,25 +1,25 @@
1
  import { MigrationInterface, QueryRunner } from "typeorm";
2
 
3
- export class RemoveAllAndAdd1730397685489 implements MigrationInterface {
4
- name = 'RemoveAllAndAdd1730397685489'
5
 
6
  public async up(queryRunner: QueryRunner): Promise<void> {
7
  await queryRunner.query(`CREATE TABLE "feeds" ("id" SERIAL NOT NULL, "author_id" character varying, "image_url" character varying, "title" character varying NOT NULL, "description" character varying, "create_at" TIMESTAMP NOT NULL DEFAULT now(), CONSTRAINT "PK_3dafbf766ecbb1eb2017732153f" PRIMARY KEY ("id"))`);
8
  await queryRunner.query(`CREATE TYPE "public"."users_role_enum" AS ENUM('CUSTOMER', 'ADMIN', 'BRANCH_MANAGER', 'AREA_MANAGER', 'STAFF', 'SHIPPER')`);
9
  await queryRunner.query(`CREATE TABLE "users" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "avatar" character varying, "full_name" character varying NOT NULL, "phone_number" character varying NOT NULL, "address" character varying, "email" character varying, "role" "public"."users_role_enum" NOT NULL DEFAULT 'CUSTOMER', "hash_password" character varying NOT NULL, "is_valid" boolean NOT NULL DEFAULT true, "create_at" TIMESTAMP NOT NULL DEFAULT now(), CONSTRAINT "UQ_17d1817f241f10a3dbafb169fd2" UNIQUE ("phone_number"), CONSTRAINT "UQ_97672ac88f789774dd47f7c8be3" UNIQUE ("email"), CONSTRAINT "PK_a3ffb1c0c8416b9fc6f907b7433" PRIMARY KEY ("id"))`);
 
10
  await queryRunner.query(`CREATE TYPE "public"."menu_items_item_type_enum" AS ENUM('monchinh', 'trangmieng', 'giaikhat', 'khac')`);
11
  await queryRunner.query(`CREATE TABLE "menu_items" ("id" character varying NOT NULL, "item_name" character varying NOT NULL, "image_url" character varying, "item_type" "public"."menu_items_item_type_enum" NOT NULL DEFAULT 'khac', "description" character varying NOT NULL, "price" integer NOT NULL, "create_at" TIMESTAMP NOT NULL DEFAULT now(), CONSTRAINT "PK_57e6188f929e5dc6919168620c8" PRIMARY KEY ("id"))`);
12
- await queryRunner.query(`CREATE TABLE "branch_menu" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "branch_id" character varying NOT NULL, "menu_id" character varying NOT NULL, "description" character varying NOT NULL, "is_open" boolean NOT NULL, "branchId" uuid, "menuItemId" character varying, CONSTRAINT "PK_977becffe98bbc626a56031b9e7" PRIMARY KEY ("id"))`);
13
- await queryRunner.query(`CREATE TABLE "branches" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "name" character varying NOT NULL, "location" character varying NOT NULL, "phone_number" character varying NOT NULL, "create_at" TIMESTAMP NOT NULL DEFAULT now(), "ownerId" uuid, CONSTRAINT "PK_7f37d3b42defea97f1df0d19535" PRIMARY KEY ("id"))`);
14
  await queryRunner.query(`CREATE TYPE "public"."payments_payment_method_enum" AS ENUM('cash', 'card', 'online_payment')`);
15
  await queryRunner.query(`CREATE TABLE "payments" ("id" SERIAL NOT NULL, "payment_method" "public"."payments_payment_method_enum" NOT NULL DEFAULT 'cash', "value" integer NOT NULL, CONSTRAINT "PK_197ab7af18c93fbb0c9b28b4a59" PRIMARY KEY ("id"))`);
16
  await queryRunner.query(`CREATE TYPE "public"."orders_order_type_enum" AS ENUM('take_away', 'offline', 'online')`);
17
  await queryRunner.query(`CREATE TYPE "public"."orders_order_status_enum" AS ENUM('pending', 'confirmed', 'preparing', 'delivering', 'done')`);
18
- await queryRunner.query(`CREATE TABLE "orders" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "customer_id" character varying, "branch_id" uuid NOT NULL, "employee_id" uuid NOT NULL, "table_number" integer, "total_value" integer NOT NULL, "create_at" TIMESTAMP NOT NULL DEFAULT now(), "order_type" "public"."orders_order_type_enum" NOT NULL DEFAULT 'online', "order_status" "public"."orders_order_status_enum" NOT NULL DEFAULT 'pending', "payment_id" integer, "customerId" uuid, "paymentId" integer, CONSTRAINT "REL_06a051324c76276ca2a9d1feb0" UNIQUE ("paymentId"), CONSTRAINT "PK_710e2d4957aa5878dfe94e4ac2f" PRIMARY KEY ("id"))`);
19
- await queryRunner.query(`CREATE TABLE "order_items" ("id" SERIAL NOT NULL, "order_id" uuid NOT NULL, "branch_menu_id" character varying NOT NULL, "quantity" integer NOT NULL, "price" integer NOT NULL, "menu_id" uuid, CONSTRAINT "PK_005269d8574e6fac0493715c308" PRIMARY KEY ("id"))`);
20
- await queryRunner.query(`ALTER TABLE "branch_menu" ADD CONSTRAINT "FK_e0c721a124fa03ea4cef6f28f42" FOREIGN KEY ("branchId") REFERENCES "branches"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
21
- await queryRunner.query(`ALTER TABLE "branch_menu" ADD CONSTRAINT "FK_cbfb42df5887653593974e3e285" FOREIGN KEY ("menuItemId") REFERENCES "menu_items"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
22
  await queryRunner.query(`ALTER TABLE "branches" ADD CONSTRAINT "FK_8c6ae9f9c654c4fac71bccbb7ed" FOREIGN KEY ("ownerId") REFERENCES "users"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
 
 
23
  await queryRunner.query(`ALTER TABLE "orders" ADD CONSTRAINT "FK_e5de51ca888d8b1f5ac25799dd1" FOREIGN KEY ("customerId") REFERENCES "users"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
24
  await queryRunner.query(`ALTER TABLE "orders" ADD CONSTRAINT "FK_17b723da2c12837f4bc21e33398" FOREIGN KEY ("branch_id") REFERENCES "branches"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
25
  await queryRunner.query(`ALTER TABLE "orders" ADD CONSTRAINT "FK_f8a7411077c731327ca6e0b93b6" FOREIGN KEY ("employee_id") REFERENCES "users"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
@@ -35,19 +35,19 @@ export class RemoveAllAndAdd1730397685489 implements MigrationInterface {
35
  await queryRunner.query(`ALTER TABLE "orders" DROP CONSTRAINT "FK_f8a7411077c731327ca6e0b93b6"`);
36
  await queryRunner.query(`ALTER TABLE "orders" DROP CONSTRAINT "FK_17b723da2c12837f4bc21e33398"`);
37
  await queryRunner.query(`ALTER TABLE "orders" DROP CONSTRAINT "FK_e5de51ca888d8b1f5ac25799dd1"`);
 
 
38
  await queryRunner.query(`ALTER TABLE "branches" DROP CONSTRAINT "FK_8c6ae9f9c654c4fac71bccbb7ed"`);
39
- await queryRunner.query(`ALTER TABLE "branch_menu" DROP CONSTRAINT "FK_cbfb42df5887653593974e3e285"`);
40
- await queryRunner.query(`ALTER TABLE "branch_menu" DROP CONSTRAINT "FK_e0c721a124fa03ea4cef6f28f42"`);
41
  await queryRunner.query(`DROP TABLE "order_items"`);
42
  await queryRunner.query(`DROP TABLE "orders"`);
43
  await queryRunner.query(`DROP TYPE "public"."orders_order_status_enum"`);
44
  await queryRunner.query(`DROP TYPE "public"."orders_order_type_enum"`);
45
  await queryRunner.query(`DROP TABLE "payments"`);
46
  await queryRunner.query(`DROP TYPE "public"."payments_payment_method_enum"`);
47
- await queryRunner.query(`DROP TABLE "branches"`);
48
  await queryRunner.query(`DROP TABLE "branch_menu"`);
49
  await queryRunner.query(`DROP TABLE "menu_items"`);
50
  await queryRunner.query(`DROP TYPE "public"."menu_items_item_type_enum"`);
 
51
  await queryRunner.query(`DROP TABLE "users"`);
52
  await queryRunner.query(`DROP TYPE "public"."users_role_enum"`);
53
  await queryRunner.query(`DROP TABLE "feeds"`);
 
1
  import { MigrationInterface, QueryRunner } from "typeorm";
2
 
3
+ export class RefactorAll1730432721785 implements MigrationInterface {
4
+ name = 'RefactorAll1730432721785'
5
 
6
  public async up(queryRunner: QueryRunner): Promise<void> {
7
  await queryRunner.query(`CREATE TABLE "feeds" ("id" SERIAL NOT NULL, "author_id" character varying, "image_url" character varying, "title" character varying NOT NULL, "description" character varying, "create_at" TIMESTAMP NOT NULL DEFAULT now(), CONSTRAINT "PK_3dafbf766ecbb1eb2017732153f" PRIMARY KEY ("id"))`);
8
  await queryRunner.query(`CREATE TYPE "public"."users_role_enum" AS ENUM('CUSTOMER', 'ADMIN', 'BRANCH_MANAGER', 'AREA_MANAGER', 'STAFF', 'SHIPPER')`);
9
  await queryRunner.query(`CREATE TABLE "users" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "avatar" character varying, "full_name" character varying NOT NULL, "phone_number" character varying NOT NULL, "address" character varying, "email" character varying, "role" "public"."users_role_enum" NOT NULL DEFAULT 'CUSTOMER', "hash_password" character varying NOT NULL, "is_valid" boolean NOT NULL DEFAULT true, "create_at" TIMESTAMP NOT NULL DEFAULT now(), CONSTRAINT "UQ_17d1817f241f10a3dbafb169fd2" UNIQUE ("phone_number"), CONSTRAINT "UQ_97672ac88f789774dd47f7c8be3" UNIQUE ("email"), CONSTRAINT "PK_a3ffb1c0c8416b9fc6f907b7433" PRIMARY KEY ("id"))`);
10
+ await queryRunner.query(`CREATE TABLE "branches" ("id" character varying NOT NULL, "name" character varying NOT NULL, "location" character varying NOT NULL, "phone_number" character varying NOT NULL, "create_at" TIMESTAMP NOT NULL DEFAULT now(), "ownerId" uuid, CONSTRAINT "PK_7f37d3b42defea97f1df0d19535" PRIMARY KEY ("id"))`);
11
  await queryRunner.query(`CREATE TYPE "public"."menu_items_item_type_enum" AS ENUM('monchinh', 'trangmieng', 'giaikhat', 'khac')`);
12
  await queryRunner.query(`CREATE TABLE "menu_items" ("id" character varying NOT NULL, "item_name" character varying NOT NULL, "image_url" character varying, "item_type" "public"."menu_items_item_type_enum" NOT NULL DEFAULT 'khac', "description" character varying NOT NULL, "price" integer NOT NULL, "create_at" TIMESTAMP NOT NULL DEFAULT now(), CONSTRAINT "PK_57e6188f929e5dc6919168620c8" PRIMARY KEY ("id"))`);
13
+ await queryRunner.query(`CREATE TABLE "branch_menu" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "branch_id" character varying NOT NULL, "menu_id" character varying NOT NULL, "description" character varying, "is_open" boolean NOT NULL DEFAULT true, CONSTRAINT "PK_977becffe98bbc626a56031b9e7" PRIMARY KEY ("id"))`);
 
14
  await queryRunner.query(`CREATE TYPE "public"."payments_payment_method_enum" AS ENUM('cash', 'card', 'online_payment')`);
15
  await queryRunner.query(`CREATE TABLE "payments" ("id" SERIAL NOT NULL, "payment_method" "public"."payments_payment_method_enum" NOT NULL DEFAULT 'cash', "value" integer NOT NULL, CONSTRAINT "PK_197ab7af18c93fbb0c9b28b4a59" PRIMARY KEY ("id"))`);
16
  await queryRunner.query(`CREATE TYPE "public"."orders_order_type_enum" AS ENUM('take_away', 'offline', 'online')`);
17
  await queryRunner.query(`CREATE TYPE "public"."orders_order_status_enum" AS ENUM('pending', 'confirmed', 'preparing', 'delivering', 'done')`);
18
+ await queryRunner.query(`CREATE TABLE "orders" ("id" SERIAL NOT NULL, "customer_id" character varying, "branch_id" character varying NOT NULL, "employee_id" uuid NOT NULL, "table_number" integer, "total_value" integer NOT NULL, "create_at" TIMESTAMP NOT NULL DEFAULT now(), "order_type" "public"."orders_order_type_enum" NOT NULL DEFAULT 'online', "order_status" "public"."orders_order_status_enum" NOT NULL DEFAULT 'pending', "payment_id" integer, "customerId" uuid, "paymentId" integer, CONSTRAINT "REL_06a051324c76276ca2a9d1feb0" UNIQUE ("paymentId"), CONSTRAINT "PK_710e2d4957aa5878dfe94e4ac2f" PRIMARY KEY ("id"))`);
19
+ await queryRunner.query(`CREATE TABLE "order_items" ("id" SERIAL NOT NULL, "order_id" integer NOT NULL, "branch_menu_id" character varying NOT NULL, "quantity" integer NOT NULL, "price" integer NOT NULL, "menu_id" uuid, CONSTRAINT "PK_005269d8574e6fac0493715c308" PRIMARY KEY ("id"))`);
 
 
20
  await queryRunner.query(`ALTER TABLE "branches" ADD CONSTRAINT "FK_8c6ae9f9c654c4fac71bccbb7ed" FOREIGN KEY ("ownerId") REFERENCES "users"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
21
+ await queryRunner.query(`ALTER TABLE "branch_menu" ADD CONSTRAINT "FK_96fd74bed807987cf2ee5d8f168" FOREIGN KEY ("branch_id") REFERENCES "branches"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
22
+ await queryRunner.query(`ALTER TABLE "branch_menu" ADD CONSTRAINT "FK_703aa953158d2e80f3fbb0eb9ea" FOREIGN KEY ("menu_id") REFERENCES "menu_items"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
23
  await queryRunner.query(`ALTER TABLE "orders" ADD CONSTRAINT "FK_e5de51ca888d8b1f5ac25799dd1" FOREIGN KEY ("customerId") REFERENCES "users"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
24
  await queryRunner.query(`ALTER TABLE "orders" ADD CONSTRAINT "FK_17b723da2c12837f4bc21e33398" FOREIGN KEY ("branch_id") REFERENCES "branches"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
25
  await queryRunner.query(`ALTER TABLE "orders" ADD CONSTRAINT "FK_f8a7411077c731327ca6e0b93b6" FOREIGN KEY ("employee_id") REFERENCES "users"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
 
35
  await queryRunner.query(`ALTER TABLE "orders" DROP CONSTRAINT "FK_f8a7411077c731327ca6e0b93b6"`);
36
  await queryRunner.query(`ALTER TABLE "orders" DROP CONSTRAINT "FK_17b723da2c12837f4bc21e33398"`);
37
  await queryRunner.query(`ALTER TABLE "orders" DROP CONSTRAINT "FK_e5de51ca888d8b1f5ac25799dd1"`);
38
+ await queryRunner.query(`ALTER TABLE "branch_menu" DROP CONSTRAINT "FK_703aa953158d2e80f3fbb0eb9ea"`);
39
+ await queryRunner.query(`ALTER TABLE "branch_menu" DROP CONSTRAINT "FK_96fd74bed807987cf2ee5d8f168"`);
40
  await queryRunner.query(`ALTER TABLE "branches" DROP CONSTRAINT "FK_8c6ae9f9c654c4fac71bccbb7ed"`);
 
 
41
  await queryRunner.query(`DROP TABLE "order_items"`);
42
  await queryRunner.query(`DROP TABLE "orders"`);
43
  await queryRunner.query(`DROP TYPE "public"."orders_order_status_enum"`);
44
  await queryRunner.query(`DROP TYPE "public"."orders_order_type_enum"`);
45
  await queryRunner.query(`DROP TABLE "payments"`);
46
  await queryRunner.query(`DROP TYPE "public"."payments_payment_method_enum"`);
 
47
  await queryRunner.query(`DROP TABLE "branch_menu"`);
48
  await queryRunner.query(`DROP TABLE "menu_items"`);
49
  await queryRunner.query(`DROP TYPE "public"."menu_items_item_type_enum"`);
50
+ await queryRunner.query(`DROP TABLE "branches"`);
51
  await queryRunner.query(`DROP TABLE "users"`);
52
  await queryRunner.query(`DROP TYPE "public"."users_role_enum"`);
53
  await queryRunner.query(`DROP TABLE "feeds"`);
backend/src/modules/branch-menus/branch-menus.controller.ts ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import {
2
+ Controller,
3
+ Get,
4
+ Post,
5
+ Body,
6
+ Patch,
7
+ Param,
8
+ Delete,
9
+ } from '@nestjs/common';
10
+ import { BranchMenusService } from './branch-menus.service.js';
11
+ import { CreateBranchMenuDto } from './dto/create-branch-menu.dto.js';
12
+ import { UpdateBranchMenuDto } from './dto/update-branch-menu.dto.js';
13
+ import { Public } from '../authentication/authentication.decorator.js';
14
+ import { Paginate, PaginateQuery } from 'nestjs-paginate';
15
+
16
+ @Public()
17
+ @Controller('branchs/:branchId/menus')
18
+ export class BranchMenusController {
19
+ constructor(private readonly branchMenusService: BranchMenusService) {}
20
+
21
+ @Post() // thêm menu vào branch
22
+ create(
23
+ @Param('branchId') branchId: string,
24
+ @Body() createBranchMenuDto: CreateBranchMenuDto,
25
+ ) {
26
+ return this.branchMenusService.create(branchId, createBranchMenuDto);
27
+ }
28
+
29
+ @Get() // lấy danh sách menu trong branch
30
+ findAll(
31
+ @Param('branchId') branchId: string,
32
+ @Paginate() query: PaginateQuery,
33
+ ) {
34
+ // console.log('branchId', branchId);
35
+ return this.branchMenusService.findAll(branchId, query);
36
+ }
37
+
38
+ @Get(':id') // lấy một menu trong branch
39
+ findOne(@Param('branchId') branchId: string, @Param('id') id: string) {
40
+ return this.branchMenusService.findOne(branchId, id);
41
+ }
42
+
43
+ @Patch(':id')
44
+ update(
45
+ @Param('id') id: string,
46
+ @Body() updateBranchMenuDto: UpdateBranchMenuDto,
47
+ ) {
48
+ return this.branchMenusService.update(+id, updateBranchMenuDto);
49
+ }
50
+
51
+ @Delete(':id')
52
+ remove(@Param('id') id: string) {
53
+ return this.branchMenusService.remove(+id);
54
+ }
55
+ }
backend/src/modules/branch-menus/branch-menus.module.ts ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { Module } from '@nestjs/common';
2
+ import { BranchMenusService } from './branch-menus.service.js';
3
+ import { BranchMenusController } from './branch-menus.controller.js';
4
+ import { BranchModule } from '../branch/branch.module.js';
5
+ import { MenuItemModule } from '../menu-item/menu-item.module.js';
6
+
7
+ @Module({
8
+ imports: [BranchModule, MenuItemModule],
9
+ controllers: [BranchMenusController],
10
+ providers: [BranchMenusService],
11
+ exports: [BranchMenusService],
12
+ })
13
+ export class BranchMenusModule {}
backend/src/modules/branch-menus/branch-menus.service.ts ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { Injectable } from '@nestjs/common';
2
+ import { CreateBranchMenuDto } from './dto/create-branch-menu.dto.js';
3
+ 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 { paginate, PaginateConfig, PaginateQuery } from 'nestjs-paginate';
8
+ import { isUUID } from 'class-validator';
9
+
10
+ @Injectable()
11
+ export class BranchMenusService {
12
+ constructor(
13
+ private readonly branchService: BranchService,
14
+ private readonly menuItemService: MenuItemService,
15
+ ) {}
16
+ async create(branchId: string, createBranchMenuDto: CreateBranchMenuDto) {
17
+ const branch = await this.branchService.getBranchOrError(branchId);
18
+ const menuItem = await this.menuItemService.getMenuItemOrError(
19
+ createBranchMenuDto.menu_id,
20
+ );
21
+ if (createBranchMenuDto.description) {
22
+ return await BranchMenuEntity.create({
23
+ ...createBranchMenuDto,
24
+ branch_id: branchId,
25
+ }).save();
26
+ } else {
27
+ return await BranchMenuEntity.create({
28
+ ...createBranchMenuDto,
29
+ branch_id: branchId,
30
+ description: menuItem.description,
31
+ }).save();
32
+ }
33
+ }
34
+
35
+ async findAll(branchId: string, query: PaginateQuery) {
36
+ const paginateConfig: PaginateConfig<BranchMenuEntity> = {
37
+ sortableColumns: ['id', 'branch_id', 'menu_id', 'description'],
38
+ nullSort: 'last',
39
+ defaultSortBy: [['id', 'DESC']],
40
+ searchableColumns: ['description'],
41
+ filterableColumns: {
42
+ // price: [],
43
+ // item_type: [FilterOperator.EQ],
44
+ },
45
+ };
46
+ return paginate(
47
+ query,
48
+ BranchMenuEntity.createQueryBuilder('bm')
49
+ .leftJoinAndSelect('bm.menu_item', 'menu_item')
50
+ .where('bm.branch_id = :branchId', { branchId: branchId }),
51
+ paginateConfig,
52
+ );
53
+ }
54
+
55
+ async findOne(branchId: string, id: string) {
56
+ if (isUUID(id)) return await BranchMenuEntity.findOneBy({ id });
57
+ else {
58
+ return await BranchMenuEntity.findOne({
59
+ where: { branch_id: branchId, menu_id: id },
60
+ relations: ['menu_item'],
61
+ });
62
+ }
63
+ }
64
+
65
+ update(id: number, updateBranchMenuDto: UpdateBranchMenuDto) {
66
+ return `This action updates a #${id} branchMenu`;
67
+ }
68
+
69
+ remove(id: number) {
70
+ return `This action removes a #${id} branchMenu`;
71
+ }
72
+ }
backend/src/modules/branch-menus/dto/create-branch-menu.dto.ts ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ import { IsOptional, IsString } from 'class-validator';
2
+
3
+ export class CreateBranchMenuDto {
4
+ @IsString()
5
+ menu_id: string;
6
+
7
+ @IsString()
8
+ @IsOptional()
9
+ description?: string;
10
+ }
backend/src/modules/branch-menus/dto/update-branch-menu.dto.ts ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ import { PartialType } from '@nestjs/mapped-types';
2
+ import { CreateBranchMenuDto } from './create-branch-menu.dto.js';
3
+
4
+ export class UpdateBranchMenuDto extends PartialType(CreateBranchMenuDto) {}
backend/src/modules/branch/branch.controller.ts CHANGED
@@ -10,8 +10,10 @@ import {
10
  import { BranchService } from './branch.service.js';
11
  import { CreateBranchDto } from './dto/create-branch.dto.js';
12
  import { UpdateBranchDto } from './dto/update-branch.dto.js';
 
13
 
14
- @Controller('branch')
 
15
  export class BranchController {
16
  constructor(private readonly branchService: BranchService) {}
17
 
@@ -47,7 +49,5 @@ export class BranchController {
47
  async addMenuItemToBranch(@Param('id') id: string) {}
48
 
49
  @Get(':id/menu-items')
50
- async getMenuItemWithBranchId(@Param('id') id: string) {
51
-
52
- }
53
  }
 
10
  import { BranchService } from './branch.service.js';
11
  import { CreateBranchDto } from './dto/create-branch.dto.js';
12
  import { UpdateBranchDto } from './dto/update-branch.dto.js';
13
+ import { Public } from '../authentication/authentication.decorator.js';
14
 
15
+ @Public()
16
+ @Controller('branchs')
17
  export class BranchController {
18
  constructor(private readonly branchService: BranchService) {}
19
 
 
49
  async addMenuItemToBranch(@Param('id') id: string) {}
50
 
51
  @Get(':id/menu-items')
52
+ async getMenuItemWithBranchId(@Param('id') id: string) {}
 
 
53
  }
backend/src/modules/branch/branch.module.ts CHANGED
@@ -5,5 +5,6 @@ import { BranchController } from './branch.controller.js';
5
  @Module({
6
  controllers: [BranchController],
7
  providers: [BranchService],
 
8
  })
9
  export class BranchModule {}
 
5
  @Module({
6
  controllers: [BranchController],
7
  providers: [BranchService],
8
+ exports: [BranchService],
9
  })
10
  export class BranchModule {}
backend/src/modules/branch/branch.service.ts CHANGED
@@ -1,4 +1,8 @@
1
- import { Injectable, NotFoundException } from '@nestjs/common';
 
 
 
 
2
  import { CreateBranchDto } from './dto/create-branch.dto.js';
3
  import { BranchEntity } from '../../entities/branch.entity.js';
4
  import { Public } from '../authentication/authentication.decorator.js';
@@ -9,6 +13,10 @@ import { plainToClass } from 'class-transformer';
9
  @Injectable()
10
  export class BranchService {
11
  async create(createBranchDto: CreateBranchDto) {
 
 
 
 
12
  return await BranchEntity.create({ ...createBranchDto }).save();
13
  }
14
 
@@ -21,9 +29,10 @@ export class BranchService {
21
  }
22
 
23
  async getBranchOrError(id: string) {
 
24
  const branch = await BranchEntity.findOneBy({ id });
25
  if (!branch) {
26
- throw new NotFoundException('Menu item not found');
27
  }
28
  return branch;
29
  }
 
1
+ import {
2
+ BadRequestException,
3
+ Injectable,
4
+ NotFoundException,
5
+ } from '@nestjs/common';
6
  import { CreateBranchDto } from './dto/create-branch.dto.js';
7
  import { BranchEntity } from '../../entities/branch.entity.js';
8
  import { Public } from '../authentication/authentication.decorator.js';
 
13
  @Injectable()
14
  export class BranchService {
15
  async create(createBranchDto: CreateBranchDto) {
16
+ const branch = await BranchEntity.findOneBy({ id: createBranchDto.id });
17
+ if (branch) {
18
+ throw new BadRequestException('Branch already exists');
19
+ }
20
  return await BranchEntity.create({ ...createBranchDto }).save();
21
  }
22
 
 
29
  }
30
 
31
  async getBranchOrError(id: string) {
32
+ console.log(id);
33
  const branch = await BranchEntity.findOneBy({ id });
34
  if (!branch) {
35
+ throw new NotFoundException('Branch not found');
36
  }
37
  return branch;
38
  }
backend/src/modules/branch/dto/create-branch.dto.ts CHANGED
@@ -1,6 +1,9 @@
1
  import { IsString } from 'class-validator';
2
 
3
  export class CreateBranchDto {
 
 
 
4
  @IsString()
5
  name: string;
6
 
 
1
  import { IsString } from 'class-validator';
2
 
3
  export class CreateBranchDto {
4
+ @IsString()
5
+ id: string;
6
+
7
  @IsString()
8
  name: string;
9
 
backend/src/modules/menu-item/menu-item.module.ts CHANGED
@@ -5,5 +5,6 @@ import { MenuItemController } from './menu-item.controller.js';
5
  @Module({
6
  controllers: [MenuItemController],
7
  providers: [MenuItemService],
 
8
  })
9
  export class MenuItemModule {}
 
5
  @Module({
6
  controllers: [MenuItemController],
7
  providers: [MenuItemService],
8
+ exports: [MenuItemService],
9
  })
10
  export class MenuItemModule {}
backend/src/modules/order/dto/create-order.dto.ts ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { IsEnum, IsNumber, IsOptional, IsString } from 'class-validator';
2
+ import { OrderType } from '../../../common/enums/OrderType.enum.js';
3
+ import { OrderItemsDto } from './order-items.dto.js';
4
+
5
+ export class CreateOrderDto {
6
+ @IsString()
7
+ customer_id: string;
8
+
9
+ @IsString()
10
+ branch_id: string;
11
+
12
+ @IsString()
13
+ employee_id: string;
14
+
15
+ @IsOptional()
16
+ @IsString()
17
+ table_number?: number;
18
+
19
+ @IsEnum(OrderType)
20
+ order_type: OrderType;
21
+
22
+
23
+ order_items: OrderItemsDto[];
24
+ }
backend/src/modules/order/dto/order-items.dto.ts ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ export class OrderItemsDto {
2
+
3
+ }
backend/src/modules/order/order.controller.ts ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import {
2
+ Controller,
3
+ Get,
4
+ Post,
5
+ Body,
6
+ Patch,
7
+ Param,
8
+ Delete,
9
+ } from '@nestjs/common';
10
+ import { OrderService } from './order.service.js';
11
+ import { CreateOrderDto } from './dto/create-order.dto.js';
12
+
13
+ @Controller('order')
14
+ export class OrderController {
15
+ constructor(private readonly orderService: OrderService) {}
16
+
17
+ @Post()
18
+ async create(@Body() createOrderDto: CreateOrderDto) {
19
+ return this.orderService.create(createOrderDto);
20
+ }
21
+
22
+ @Get()
23
+ async findAll() {
24
+ return this.orderService.findAll();
25
+ }
26
+
27
+ @Get(':id')
28
+ async findOne(@Param('id') id: string) {
29
+ return this.orderService.findOne(+id);
30
+ }
31
+
32
+ // @Patch(':id')
33
+ // async update(
34
+ // @Param('id') id: string,
35
+ // @Body() updateOrderDto: UpdateOrderDto,
36
+ // ) {
37
+ // return this.orderService.update(+id, updateOrderDto);
38
+ // }
39
+
40
+ @Delete(':id')
41
+ remove(@Param('id') id: string) {
42
+ return this.orderService.remove(+id);
43
+ }
44
+ }
backend/src/modules/order/order.module.ts ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ import { Module } from '@nestjs/common';
2
+ import { OrderService } from './order.service.js';
3
+ import { OrderController } from './order.controller.js';
4
+
5
+ @Module({
6
+ controllers: [OrderController],
7
+ providers: [OrderService],
8
+ })
9
+ export class OrderModule {}
backend/src/modules/order/order.service.ts ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { Injectable } from '@nestjs/common';
2
+ import { CreateOrderDto } from './dto/create-order.dto.js';
3
+
4
+ @Injectable()
5
+ export class OrderService {
6
+ create(createOrderDto: CreateOrderDto) {
7
+ return 'This action adds a new order';
8
+ }
9
+
10
+ findAll() {
11
+ return `This action returns all order`;
12
+ }
13
+
14
+ findOne(id: number) {
15
+ return `This action returns a #${id} order`;
16
+ }
17
+
18
+ remove(id: number) {
19
+ return `This action removes a #${id} order`;
20
+ }
21
+ }