Skip to content

Commit

Permalink
Fes 83 create order (#79)
Browse files Browse the repository at this point in the history
* create order & update order logic

* get driver infor and adjust table to get share_link

* create ahamove order

* create ahamove order

* build other data for order detail response

---------

Co-authored-by: NHT <[email protected]>
  • Loading branch information
nfesta2023 and hoangtuan910 authored Mar 18, 2024
1 parent c78267b commit 672f28a
Show file tree
Hide file tree
Showing 30 changed files with 2,168 additions and 389 deletions.
2 changes: 2 additions & 0 deletions src/config/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ export default () => ({
featureFlag: process.env.FEATURE_FLAG || '',
ahamoveToken: process.env.AHAMOVE_TOKEN,
planningDay: 7, // the restaurant will plan new cooking schedule every Saturday (last until the end of the day)
timeStepInTimSlotConverterM: 15, //minutes
deliverBufferTime: 5, //minutes
});
17 changes: 17 additions & 0 deletions src/database/migrations/1710669092619-UpdateAhamoveOrder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class UpdateAhamoveOrder1710669092619 implements MigrationInterface {
name = 'UpdateAhamoveOrder1710669092619';

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE \`Ahamove_Order\` ADD COLUMN \`shared_link\` VARCHAR(2048) NOT NULL AFTER \`response\``,
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE \`Ahamove_Order\` DROP COLUMN \`shared_link\` `,
);
}
}
1 change: 0 additions & 1 deletion src/dependency/ahamove/ahamove.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { TypeOrmModule } from '@nestjs/typeorm';
import { AhamoveOrderEntity } from 'src/entity/ahamove-order.entity';
import { AhamoveOrderHookEntity } from 'src/entity/ahamove-order-hook.entity';
import { InvoiceStatusHistoryModule } from 'src/feature/invoice-status-history/invoice-status-history.module';
import { OrderModule } from 'src/feature/order/order.module';

@Module({
imports: [
Expand Down
1 change: 1 addition & 0 deletions src/dependency/ahamove/ahamove.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ export class AhamoveService implements OnModuleInit {
const { data } = await axios.request(config);
// update order id and response from ahamove
orderRequest.order_id = data.order_id;
orderRequest.shared_link = data.shared_link;
orderRequest.response = data;
const result = await this.ahamoveOrder.save(
AhamoveMapper.fromDTOtoEntity(orderRequest),
Expand Down
1 change: 1 addition & 0 deletions src/dependency/ahamove/dto/ahamove.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export interface AhamoveOrder {
group_requests: null | string;
order_id?: string;
response: string;
shared_link?: string;
}

export interface PostAhaOrderRequest {
Expand Down
18 changes: 16 additions & 2 deletions src/entity/ahamove-order.entity.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
import { AhaMoveRequest, Item, PackageDetail } from 'src/dependency/ahamove/dto/ahamove.dto';
import {
AhaMoveRequest,
Item,
PackageDetail,
} from 'src/dependency/ahamove/dto/ahamove.dto';
import { PathLocation } from 'src/dependency/ahamove/dto/ahamove.hook';
import { Entity, PrimaryGeneratedColumn, Column, OneToMany, ManyToOne, JoinColumn } from 'typeorm';
import {
Entity,
PrimaryGeneratedColumn,
Column,
OneToMany,
ManyToOne,
JoinColumn,
} from 'typeorm';

@Entity('Ahamove_Order')
export class AhamoveOrderEntity {
Expand Down Expand Up @@ -57,4 +68,7 @@ export class AhamoveOrderEntity {

@Column({ nullable: true })
group_requests: string | null;

@Column({ type: 'varchar', length: 2048, nullable: true })
shared_link: string;
}
63 changes: 63 additions & 0 deletions src/entity/customer.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import {
Column,
CreateDateColumn,
Entity,
JoinColumn,
OneToOne,
PrimaryGeneratedColumn,
} from 'typeorm';
import { Media } from './media.entity';

@Entity('Customer')
export class Customer {
@PrimaryGeneratedColumn()
public customer_id: number;

@Column({ type: 'varchar', length: 25, nullable: false, unique: true })
public phone_number: string;

@Column({ type: 'varchar', length: 255, nullable: true, unique: false })
public name: string;

@Column({ type: 'varchar', length: 255, nullable: true, unique: false })
public email: string;

@Column({ type: 'date', nullable: true, unique: false })
public birthday: Date;

@Column({ type: 'char', length: 1, nullable: true, unique: false })
public sex: string;

@OneToOne(() => Media)
@JoinColumn({
name: 'profile_image',
referencedColumnName: 'media_id',
})
public profile_image: Media;

@Column({
type: 'tinyint',
nullable: false,
unique: false,
default: 0,
})
public is_active: number;

// @OneToOne(() => HealthInfo)
// @JoinColumn({
// name: 'health_info_id',
// referencedColumnName: 'health_info_id',
// })
// public health_info: HealthInfo;

@Column({ type: 'varchar', length: 255, nullable: true, unique: false })
public refresh_token: string;

@CreateDateColumn({
type: 'datetime',
nullable: false,
unique: false,
default: () => 'CURRENT_TIMESTAMP',
})
public created_at: Date;
}
11 changes: 6 additions & 5 deletions src/entity/driver-status-log.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,24 @@ export class DriverStatusLog {
@PrimaryGeneratedColumn('uuid')
log_id: string;

@Column()
@Column({ type: 'int', nullable: false, unique: false })
order_id: number;

@Column({ nullable: true })
@Column({ type: 'int', nullable: true, unique: false })
driver_id: number | null;

@Column('text', { nullable: true })
@Column('text', { nullable: true, unique: false })
note: string | null;

@Column('bigint')
logged_at: number;

//RELATIONSHIP
@ManyToOne(() => Order)
@JoinColumn({ name: 'order_id' })
@JoinColumn({ name: 'order_id', referencedColumnName: 'order_id' })
order: Order;

@ManyToOne(() => Driver, { nullable: true })
@JoinColumn({ name: 'driver_id' })
@JoinColumn({ name: 'driver_id', referencedColumnName: 'driver_id' })
driver: Driver | null;
}
25 changes: 18 additions & 7 deletions src/entity/driver.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,29 @@ import {
PrimaryGeneratedColumn,
Column,
CreateDateColumn,
ManyToOne,
JoinColumn,
} from 'typeorm';
import { Media } from './media.entity';

@Entity('Driver')
export class Driver {
@PrimaryGeneratedColumn()
driver_id: number;

@Column({ length: 255 })
@Column({ type: 'varchar', length: 255, nullable: false, unique: false })
name: string;

@Column({ length: 25, nullable: true })
@Column({ type: 'varchar', length: 25, nullable: true, unique: false })
phone_number: string | null;

@Column({ length: 255, nullable: true })
@Column({ type: 'varchar', length: 255, nullable: true, unique: false })
email: string | null;

@Column({ length: 255, nullable: true })
@Column({ type: 'varchar', length: 255, nullable: true, unique: false })
vehicle: string | null;

@Column({ length: 48, nullable: true })
@Column({ type: 'varchar', length: 48, nullable: true, unique: false })
license_plates: string | null;

@Column({
Expand All @@ -32,10 +35,10 @@ export class Driver {
})
type: 'AHAMOVE' | 'ONWHEEL' | null;

@Column({ length: 255, nullable: true })
@Column({ type: 'varchar', length: 255, nullable: true, unique: false })
reference_id: string;

@Column({ type: 'int', nullable: true })
@Column({ type: 'int', nullable: true, unique: false })
profile_image: number;

@CreateDateColumn({
Expand All @@ -45,4 +48,12 @@ export class Driver {
default: () => 'CURRENT_TIMESTAMP',
})
public created_at: Date;

//RELATIONSHIP
@ManyToOne(() => Media)
@JoinColumn({
name: 'profile_image',
referencedColumnName: 'media_id',
})
profile_image_obj: Media;
}
40 changes: 32 additions & 8 deletions src/entity/ingredient.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,41 @@ export class Ingredient {
@Column({ type: 'varchar', length: 255, nullable: true, unique: false })
public eng_name: string;

@Column({ type: 'int', nullable: true, unique: false })
public calorie_kcal: number;
@Column({
type: 'decimal',
precision: 10,
scale: 2,
nullable: true,
unique: false,
})
public calorie_kcal: string;

@Column({ type: 'int', nullable: true, unique: false })
public protein_g: number;
@Column({
type: 'decimal',
precision: 10,
scale: 2,
nullable: true,
unique: false,
})
public protein_g: string;

@Column({ type: 'int', nullable: true, unique: false })
public fat_g: number;
@Column({
type: 'decimal',
precision: 10,
scale: 2,
nullable: true,
unique: false,
})
public fat_g: string;

@Column({ type: 'int', nullable: true, unique: false })
public carbohydrate_g: number;
@Column({
type: 'decimal',
precision: 10,
scale: 2,
nullable: true,
unique: false,
})
public carbohydrate_g: string;

@Column({ type: 'varchar', length: 10, nullable: true, unique: false })
public ma_BTP2007: string;
Expand Down
27 changes: 20 additions & 7 deletions src/entity/invoice-history-status.entity.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,52 @@
import {
Entity,
PrimaryColumn,
Column,
PrimaryGeneratedColumn,
ManyToOne,
JoinColumn,
CreateDateColumn,
OneToMany,
} from 'typeorm';
import { Invoice } from './invoice.entity';
import { InvoiceStatusExt } from './invoice-status-ext.entity';

@Entity('Invoice_Status_History')
export class InvoiceStatusHistory {
@PrimaryColumn({
type: 'varchar',
length: 36,
})
@PrimaryGeneratedColumn('uuid')
status_history_id: string;

@Column({
type: 'int',
nullable: false,
unique: false,
})
invoice_id: number;

@Column({
type: 'varchar',
length: 64,
nullable: true,
unique: false,
})
status_id: string | null;

@Column({
type: 'text',
nullable: true,
unique: false,
})
note: string | null;

@Column({ type: 'bigint', nullable: false })
@Column({ type: 'bigint', nullable: false, unique: false })
created_at: number;

//RELATIONSHIP
@ManyToOne(() => Invoice, (invoice) => invoice.history_status_obj)
@JoinColumn({
name: 'invoice_id',
referencedColumnName: 'invoice_id',
})
public invoice_obj: Invoice;

@OneToMany(() => InvoiceStatusExt, (ext) => ext.invoice_status_history)
public invoice_status_ext: InvoiceStatusExt[];
}
40 changes: 40 additions & 0 deletions src/entity/invoice-status-ext.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import {
Column,
Entity,
PrimaryColumn,
CreateDateColumn,
ManyToOne,
JoinColumn,
} from 'typeorm';
import { InvoiceStatusHistory } from './invoice-history-status.entity';

@Entity('Invoice_Status_Ext')
export class InvoiceStatusExt {
@PrimaryColumn()
public status_id: string;

@PrimaryColumn()
public ISO_language_code: string;

@Column({ type: 'varchar', length: 64, nullable: false, unique: false })
public name: string;

@CreateDateColumn({
type: 'datetime',
nullable: false,
unique: false,
default: () => 'CURRENT_TIMESTAMP',
})
public created_at: Date;

//RELATIONSHIP
@ManyToOne(
() => InvoiceStatusHistory,
(history) => history.invoice_status_ext,
)
@JoinColumn({
name: 'status_id',
referencedColumnName: 'status_id',
})
public invoice_status_history: InvoiceStatusHistory;
}
Loading

0 comments on commit 672f28a

Please sign in to comment.