Skip to content

Commit 7670539

Browse files
committed
feat(third-party): ✨ add giaohangnhanh
1 parent 53ba6a6 commit 7670539

18 files changed

Lines changed: 524 additions & 5 deletions

.vscode/settings.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"cSpell.words": ["casl", "clipboardy", "pino", "Redlock", "virtuals"],
2+
"cSpell.words": ["casl", "clipboardy", "giaohangnhanh", "pino", "Redlock", "virtuals"],
33
"conventionalCommits.scopes": [
44
"seed",
55
"lib/common",
@@ -12,6 +12,7 @@
1212
"swagger",
1313
"ssl/tls",
1414
"scripts",
15-
"mail"
15+
"mail",
16+
"third-party"
1617
]
1718
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import { IsEnum } from 'class-validator';
2+
import { SupportTypeEnum, StatusEnum } from '../enums';
3+
import { ApiProperty } from '@nestjs/swagger';
4+
import { GhnDistrict } from 'giaohangnhanh';
5+
6+
export class GhnDistrictDTO {
7+
constructor(data: GhnDistrict) {
8+
this.district_id = Number(data.DistrictID);
9+
this.district_name = data.DistrictName;
10+
this.support_type = Number(data.SupportType);
11+
this.name_extension = data.NameExtension;
12+
this.can_update_cod = Boolean(data.CanUpdateCOD);
13+
this.status = Number(data.Status);
14+
}
15+
16+
@ApiProperty({
17+
example: 201,
18+
description: 'Mã tỉnh thành',
19+
type: Number,
20+
})
21+
province_id: number;
22+
23+
@ApiProperty({
24+
example: 1490,
25+
description: 'Mã quận huyện',
26+
type: Number,
27+
})
28+
district_id: number;
29+
30+
@ApiProperty({
31+
example: 'Quận Hoàng Mai',
32+
description: 'Tên quận huyện',
33+
type: String,
34+
})
35+
district_name: string;
36+
37+
@ApiProperty({
38+
example: 1,
39+
description: 'Loại hỗ trợ',
40+
type: Number,
41+
enum: SupportTypeEnum,
42+
})
43+
@IsEnum(SupportTypeEnum)
44+
support_type: number;
45+
46+
@ApiProperty({
47+
example: [
48+
'Quận Hoàng Mai',
49+
'Q.Hoàng Mai',
50+
'Q Hoàng Mai',
51+
'Hoàng Mai',
52+
'Hoang Mai',
53+
'Quan Hoang Mai',
54+
'hoangmai',
55+
],
56+
description: 'Tên quận huyện mở rộng',
57+
type: [String],
58+
})
59+
name_extension: string[];
60+
61+
@ApiProperty({
62+
example: true,
63+
description: 'Có thể cập nhật COD',
64+
type: Boolean,
65+
})
66+
can_update_cod: boolean;
67+
68+
@ApiProperty({
69+
example: 1,
70+
description: 'Trạng thái',
71+
type: Number,
72+
enum: StatusEnum,
73+
})
74+
@IsEnum(StatusEnum)
75+
@ApiProperty({
76+
example: 1,
77+
description: 'Trạng thái',
78+
type: Number,
79+
enum: StatusEnum,
80+
})
81+
status: number;
82+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import { IsNumber, IsOptional, IsString } from 'class-validator';
2+
3+
export class ItemShipping {
4+
constructor(partial: ItemShipping) {
5+
this.name = partial.name;
6+
this.quantity = partial.quantity;
7+
this.height = partial.height;
8+
this.weight = partial.weight;
9+
this.width = partial.width;
10+
this.length = partial.length;
11+
this.code = partial?.code ? partial.code : undefined;
12+
}
13+
14+
name: string;
15+
code?: string;
16+
quantity: number;
17+
height: number;
18+
weight: number;
19+
width: number;
20+
length: number;
21+
}
22+
23+
export class GetShippingFeeDTO {
24+
constructor(data: GetShippingFeeDTO) {
25+
this.service_type_id = data?.service_type_id;
26+
this.from_district_id = data?.from_district_id;
27+
this.from_ward_code = data?.from_ward_code;
28+
this.to_district_id = data?.to_district_id;
29+
this.to_ward_code = data?.to_ward_code;
30+
this.height = data?.height;
31+
this.weight = data?.weight;
32+
this.width = data?.width;
33+
this.length = data?.length;
34+
this.insurance_value = data?.insurance_value;
35+
this.items = data?.items.map((item) => new ItemShipping(item));
36+
this.province_id = data?.province_id;
37+
}
38+
39+
@IsOptional()
40+
@IsNumber()
41+
service_type_id?: number;
42+
43+
@IsNumber()
44+
from_district_id?: number;
45+
46+
@IsOptional()
47+
from_ward_code?: string;
48+
49+
@IsNumber()
50+
to_district_id: number;
51+
52+
@IsString()
53+
to_ward_code: string;
54+
55+
height: number;
56+
weight: number;
57+
width: number;
58+
length: number;
59+
60+
insurance_value?: number;
61+
items: ItemShipping[];
62+
63+
province_id?: number;
64+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export * from './district.dto';
2+
export * from './province.dto';
3+
export * from './ward.dto';
4+
export * from './get-shipping-fee.dto';
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import { IsArray, IsEnum, IsNotEmpty, IsNumber, IsString } from 'class-validator';
2+
import { StatusEnum } from '../enums';
3+
import { ApiProperty } from '@nestjs/swagger';
4+
import { GhnProvince } from 'giaohangnhanh';
5+
6+
export class GhnProvinceDTO {
7+
constructor(data: GhnProvince) {
8+
this.province_id = Number(data.ProvinceID);
9+
this.province_name = data.ProvinceName;
10+
this.country_id = Number(data.CountryID);
11+
this.name_extension = data.NameExtension;
12+
this.status = Number(data.Status);
13+
}
14+
15+
@ApiProperty({
16+
example: 201,
17+
description: 'Mã tỉnh thành',
18+
type: Number,
19+
})
20+
@IsNumber()
21+
@IsNotEmpty()
22+
province_id: number;
23+
24+
@ApiProperty({
25+
example: 'Hà Nội',
26+
description: 'Tên tỉnh thành',
27+
type: String,
28+
})
29+
@IsString()
30+
@IsNotEmpty()
31+
province_name: string;
32+
33+
@ApiProperty({
34+
example: 1,
35+
description: 'Mã quốc gia',
36+
type: Number,
37+
})
38+
@IsNumber()
39+
@IsNotEmpty()
40+
country_id: number;
41+
42+
@ApiProperty({
43+
example: [
44+
'Hà Nội',
45+
'TP.Hà Nội',
46+
'TP. Hà Nội',
47+
'TP Hà Nội',
48+
'Thành phố Hà Nội',
49+
'hanoi',
50+
'HN',
51+
'ha noi',
52+
],
53+
description: 'Tên tỉnh thành mở rộng',
54+
type: [String],
55+
})
56+
@IsArray()
57+
name_extension: string[];
58+
59+
@ApiProperty({
60+
example: 1,
61+
description: 'Trạng thái',
62+
type: Number,
63+
enum: StatusEnum,
64+
})
65+
@IsEnum(StatusEnum)
66+
status: number;
67+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import { IsEnum } from 'class-validator';
2+
import { StatusEnum, SupportTypeEnum } from '../enums';
3+
import { ApiProperty } from '@nestjs/swagger';
4+
import { GhnWard } from 'giaohangnhanh';
5+
6+
export class GhnWardDTO {
7+
constructor(data: GhnWard) {
8+
this.district_id = Number(data.DistrictID);
9+
this.ward_code = data.WardCode;
10+
this.ward_name = data.WardName;
11+
this.support_type = Number(data.SupportType);
12+
this.name_extension = data.NameExtension;
13+
this.can_update_cod = Boolean(data.CanUpdateCOD);
14+
this.status = Number(data.Status);
15+
}
16+
17+
@ApiProperty({
18+
type: Number,
19+
example: 1490,
20+
description: 'Mã quận huyện',
21+
})
22+
district_id: number;
23+
24+
@ApiProperty({
25+
type: String,
26+
example: '1A0807',
27+
description: 'Mã phường xã',
28+
})
29+
ward_code: string;
30+
31+
@ApiProperty({
32+
type: String,
33+
example: 'Phường Mai Động',
34+
description: 'Tên phường xã',
35+
})
36+
ward_name: string;
37+
38+
@ApiProperty({
39+
type: [String],
40+
description: 'Tên phường xã mở rộng',
41+
example: [
42+
'Phường Mai Động',
43+
'P.Mai Động',
44+
'P Mai Động',
45+
'Mai Động',
46+
'Mai Dong',
47+
'Phuong Mai Dong',
48+
'maidong',
49+
],
50+
})
51+
name_extension: string[];
52+
53+
@ApiProperty({
54+
type: Number,
55+
example: 1,
56+
description: 'Loại hỗ trợ',
57+
enum: SupportTypeEnum,
58+
})
59+
@IsEnum(SupportTypeEnum)
60+
support_type: number;
61+
62+
@ApiProperty({
63+
type: Boolean,
64+
example: true,
65+
description: 'Có thể cập nhật COD',
66+
})
67+
can_update_cod: boolean;
68+
69+
@ApiProperty({
70+
type: Number,
71+
example: 1,
72+
description: 'Trạng thái',
73+
enum: StatusEnum,
74+
})
75+
@IsEnum(StatusEnum)
76+
status: number;
77+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export enum StatusEnum {
2+
enable_route = 1,
3+
disable_route = 2,
4+
}
5+
6+
export enum SupportTypeEnum {
7+
lock_route = 0,
8+
pickup_return = 1,
9+
delivery = 2,
10+
pickup_delivery_and_return = 3,
11+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './ghn.enum';
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { DynamicModule, Module } from '@nestjs/common';
2+
import { GhnService } from './ghn.service';
3+
import { GhnConfig } from 'giaohangnhanh';
4+
import { RedisModule } from '~/common/redis';
5+
6+
@Module({
7+
imports: [RedisModule],
8+
})
9+
export class GhnModule {
10+
static forRoot(config: GhnConfig): DynamicModule {
11+
return {
12+
module: GhnModule,
13+
providers: [
14+
{
15+
provide: 'GHN_INIT_OPTIONS',
16+
useValue: config,
17+
},
18+
GhnService,
19+
],
20+
exports: [GhnService],
21+
};
22+
}
23+
}

0 commit comments

Comments
 (0)