Spaces:
Sleeping
Sleeping
Trần Viết Sơn
commited on
Commit
•
766d2fb
1
Parent(s):
9e8f9e3
feat: export service
Browse files- backend/src/common/enums/OrderStatus.enum.ts +3 -3
- backend/src/entities/order.entity.ts +3 -0
- backend/src/migrations/{1730801455870-AddOrderAndPayment.ts → 1730865796585-AddBranchAndOrderFields.ts} +4 -2
- backend/src/modules/order/order.controller.ts +2 -0
- backend/src/modules/order/order.module.ts +1 -0
- backend/src/modules/order/order.service.ts +37 -2
backend/src/common/enums/OrderStatus.enum.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
export enum OrderStatus {
|
2 |
-
PENDING = 0, //
|
3 |
-
|
4 |
-
PREPARING = 2, // nhân viên xác nhận và sang trạng thái preparing
|
5 |
DELIVERING = 3, // dang giao hàng <online>
|
6 |
DONE = 4, // <online, offline>
|
7 |
}
|
|
|
1 |
export enum OrderStatus {
|
2 |
+
PENDING = 0, // Khách hàng đặt hàng chưa thanh toán <online>
|
3 |
+
ONLINE_PAID = 1, // Khách hàng đã thanh toán và được nhân viên xác nhận <online>
|
4 |
+
PREPARING = 2, // nhân viên xác nhận và sang trạng thái preparing <online/offline>
|
5 |
DELIVERING = 3, // dang giao hàng <online>
|
6 |
DONE = 4, // <online, offline>
|
7 |
}
|
backend/src/entities/order.entity.ts
CHANGED
@@ -49,6 +49,9 @@ export class OrderEntity extends BaseEntity {
|
|
49 |
@Column({ nullable: true })
|
50 |
note: string;
|
51 |
|
|
|
|
|
|
|
52 |
@Column()
|
53 |
total_value: number;
|
54 |
|
|
|
49 |
@Column({ nullable: true })
|
50 |
note: string;
|
51 |
|
52 |
+
@Column({ nullable: true })
|
53 |
+
rating: number;
|
54 |
+
|
55 |
@Column()
|
56 |
total_value: number;
|
57 |
|
backend/src/migrations/{1730801455870-AddOrderAndPayment.ts → 1730865796585-AddBranchAndOrderFields.ts}
RENAMED
@@ -1,16 +1,18 @@
|
|
1 |
import { MigrationInterface, QueryRunner } from "typeorm";
|
2 |
|
3 |
-
export class
|
4 |
-
name = '
|
5 |
|
6 |
public async up(queryRunner: QueryRunner): Promise<void> {
|
7 |
await queryRunner.query(`ALTER TABLE "feeds" ADD "delete_at" TIMESTAMP`);
|
8 |
await queryRunner.query(`ALTER TABLE "menu_items" ADD "delete_at" TIMESTAMP`);
|
9 |
await queryRunner.query(`ALTER TABLE "branches" ADD "delete_at" TIMESTAMP`);
|
10 |
await queryRunner.query(`ALTER TABLE "orders" ADD "note" character varying`);
|
|
|
11 |
}
|
12 |
|
13 |
public async down(queryRunner: QueryRunner): Promise<void> {
|
|
|
14 |
await queryRunner.query(`ALTER TABLE "orders" DROP COLUMN "note"`);
|
15 |
await queryRunner.query(`ALTER TABLE "branches" DROP COLUMN "delete_at"`);
|
16 |
await queryRunner.query(`ALTER TABLE "menu_items" DROP COLUMN "delete_at"`);
|
|
|
1 |
import { MigrationInterface, QueryRunner } from "typeorm";
|
2 |
|
3 |
+
export class AddBranchAndOrderFields1730865796585 implements MigrationInterface {
|
4 |
+
name = 'AddBranchAndOrderFields1730865796585'
|
5 |
|
6 |
public async up(queryRunner: QueryRunner): Promise<void> {
|
7 |
await queryRunner.query(`ALTER TABLE "feeds" ADD "delete_at" TIMESTAMP`);
|
8 |
await queryRunner.query(`ALTER TABLE "menu_items" ADD "delete_at" TIMESTAMP`);
|
9 |
await queryRunner.query(`ALTER TABLE "branches" ADD "delete_at" TIMESTAMP`);
|
10 |
await queryRunner.query(`ALTER TABLE "orders" ADD "note" character varying`);
|
11 |
+
await queryRunner.query(`ALTER TABLE "orders" ADD "rating" integer`);
|
12 |
}
|
13 |
|
14 |
public async down(queryRunner: QueryRunner): Promise<void> {
|
15 |
+
await queryRunner.query(`ALTER TABLE "orders" DROP COLUMN "rating"`);
|
16 |
await queryRunner.query(`ALTER TABLE "orders" DROP COLUMN "note"`);
|
17 |
await queryRunner.query(`ALTER TABLE "branches" DROP COLUMN "delete_at"`);
|
18 |
await queryRunner.query(`ALTER TABLE "menu_items" DROP COLUMN "delete_at"`);
|
backend/src/modules/order/order.controller.ts
CHANGED
@@ -41,6 +41,8 @@ export class OrderController {
|
|
41 |
|
42 |
@Get()
|
43 |
async findAll(@Req() req: Request) {
|
|
|
|
|
44 |
const userId = req['user'].sub;
|
45 |
console.log(req['user']);
|
46 |
return this.orderService.findAll();
|
|
|
41 |
|
42 |
@Get()
|
43 |
async findAll(@Req() req: Request) {
|
44 |
+
// order history of user.
|
45 |
+
// if customer, view history.
|
46 |
const userId = req['user'].sub;
|
47 |
console.log(req['user']);
|
48 |
return this.orderService.findAll();
|
backend/src/modules/order/order.module.ts
CHANGED
@@ -8,5 +8,6 @@ import { BranchMenusModule } from '../branch-menus/branch-menus.module.js';
|
|
8 |
imports: [BranchModule, BranchMenusModule],
|
9 |
controllers: [OrderController],
|
10 |
providers: [OrderService],
|
|
|
11 |
})
|
12 |
export class OrderModule {}
|
|
|
8 |
imports: [BranchModule, BranchMenusModule],
|
9 |
controllers: [OrderController],
|
10 |
providers: [OrderService],
|
11 |
+
exports: [OrderService],
|
12 |
})
|
13 |
export class OrderModule {}
|
backend/src/modules/order/order.service.ts
CHANGED
@@ -1,4 +1,8 @@
|
|
1 |
-
import {
|
|
|
|
|
|
|
|
|
2 |
import { CreateOrderDto } from './dto/create-order.dto.js';
|
3 |
import { UserEntity } from '../../entities/user.entity.js';
|
4 |
import { OrderEntity } from '../../entities/order.entity.js';
|
@@ -123,8 +127,39 @@ export class OrderService {
|
|
123 |
return { ...order, order_items: orderItems };
|
124 |
}
|
125 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
126 |
findAll() {
|
127 |
-
//
|
128 |
return `This action returns all order`;
|
129 |
}
|
130 |
|
|
|
1 |
+
import {
|
2 |
+
BadRequestException,
|
3 |
+
Injectable,
|
4 |
+
NotFoundException,
|
5 |
+
} from '@nestjs/common';
|
6 |
import { CreateOrderDto } from './dto/create-order.dto.js';
|
7 |
import { UserEntity } from '../../entities/user.entity.js';
|
8 |
import { OrderEntity } from '../../entities/order.entity.js';
|
|
|
127 |
return { ...order, order_items: orderItems };
|
128 |
}
|
129 |
|
130 |
+
/**
|
131 |
+
* Lấy order kèm với list item
|
132 |
+
*/
|
133 |
+
async findOrderOrError(id: number) {
|
134 |
+
const order = await OrderEntity.findOne({
|
135 |
+
where: { id },
|
136 |
+
relations: ['menu_item'],
|
137 |
+
});
|
138 |
+
if (!order) {
|
139 |
+
throw new NotFoundException('Order id not found');
|
140 |
+
}
|
141 |
+
return order;
|
142 |
+
}
|
143 |
+
|
144 |
+
/**
|
145 |
+
* Xem cụ thể OrderStatus để biết trạng thái,
|
146 |
+
*/
|
147 |
+
async updateOrderStatus(id: number, status: OrderStatus) {
|
148 |
+
// cập nhật trạng thái paid
|
149 |
+
const order = await this.findOrderOrError(id);
|
150 |
+
order.order_status = status;
|
151 |
+
await order.save();
|
152 |
+
}
|
153 |
+
|
154 |
+
/**
|
155 |
+
* Lấy danh sách order theo
|
156 |
+
* - Chi nhánh
|
157 |
+
* - Nhân viên duyệt
|
158 |
+
* - Trạng thái
|
159 |
+
*
|
160 |
+
*/
|
161 |
findAll() {
|
162 |
+
//
|
163 |
return `This action returns all order`;
|
164 |
}
|
165 |
|