@hed-hog/address 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/address.controller.d.ts +35 -0
- package/dist/address.controller.d.ts.map +1 -0
- package/dist/address.controller.js +90 -0
- package/dist/address.controller.js.map +1 -0
- package/dist/address.module.d.ts +3 -0
- package/dist/address.module.d.ts.map +1 -0
- package/dist/address.module.js +33 -0
- package/dist/address.module.js.map +1 -0
- package/dist/address.service.d.ts +38 -0
- package/dist/address.service.d.ts.map +1 -0
- package/dist/address.service.js +124 -0
- package/dist/address.service.js.map +1 -0
- package/dist/dto/create.dto.d.ts +20 -0
- package/dist/dto/create.dto.d.ts.map +1 -0
- package/dist/dto/create.dto.js +81 -0
- package/dist/dto/create.dto.js.map +1 -0
- package/dist/dto/update.dto.d.ts +6 -0
- package/dist/dto/update.dto.d.ts.map +1 -0
- package/dist/dto/update.dto.js +9 -0
- package/dist/dto/update.dto.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/hedhog/data/role.yaml +7 -0
- package/hedhog/data/route.yaml +20 -0
- package/hedhog/table/address.yaml +28 -0
- package/package.json +37 -0
- package/src/address.controller.ts +56 -0
- package/src/address.module.ts +20 -0
- package/src/address.service.ts +163 -0
- package/src/dto/create.dto.ts +56 -0
- package/src/dto/update.dto.ts +4 -0
- package/src/index.ts +5 -0
- package/src/language/en.json +23 -0
- package/src/language/pt.json +23 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { DeleteDTO } from '@hed-hog/api';
|
|
2
|
+
import { AddressService } from './address.service';
|
|
3
|
+
import { CreateDTO } from './dto/create.dto';
|
|
4
|
+
import { UpdateDTO } from './dto/update.dto';
|
|
5
|
+
export declare class AddressController {
|
|
6
|
+
private readonly addressService;
|
|
7
|
+
constructor(addressService: AddressService);
|
|
8
|
+
list(paginationParams: any): Promise<{
|
|
9
|
+
total: any;
|
|
10
|
+
lastPage: number;
|
|
11
|
+
page: number;
|
|
12
|
+
pageSize: number;
|
|
13
|
+
prev: number;
|
|
14
|
+
next: number;
|
|
15
|
+
data: any[];
|
|
16
|
+
}>;
|
|
17
|
+
get(id: number, locale: string): Promise<{
|
|
18
|
+
id: number;
|
|
19
|
+
person_id: number;
|
|
20
|
+
address_type_id: number;
|
|
21
|
+
country_code: string;
|
|
22
|
+
state: string;
|
|
23
|
+
city: string;
|
|
24
|
+
postal_code: string;
|
|
25
|
+
line1: string;
|
|
26
|
+
line2: string;
|
|
27
|
+
is_primary: boolean;
|
|
28
|
+
created_at: Date;
|
|
29
|
+
updated_at: Date;
|
|
30
|
+
}>;
|
|
31
|
+
create(data: CreateDTO, locale: string): Promise<any>;
|
|
32
|
+
update(id: number, data: UpdateDTO, locale: string): Promise<any>;
|
|
33
|
+
delete(data: DeleteDTO, locale: string): Promise<import("@prisma/client").Prisma.BatchPayload>;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=address.controller.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"address.controller.d.ts","sourceRoot":"","sources":["../src/address.controller.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAQ,MAAM,cAAc,CAAC;AAe/C,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAE7C,qBAEa,iBAAiB;IAG1B,OAAO,CAAC,QAAQ,CAAC,cAAc;gBAAd,cAAc,EAAE,cAAc;IAI3C,IAAI,CAAe,gBAAgB,KAAA;;;;;;;;;IAKnC,GAAG,CAA4B,EAAE,EAAE,MAAM,EAAY,MAAM,EAAE,MAAM;;;;;;;;;;;;;;IAKnE,MAAM,CAAS,IAAI,EAAE,SAAS,EAAY,MAAM,EAAE,MAAM;IAKxD,MAAM,CACiB,EAAE,EAAE,MAAM,EAC7B,IAAI,EAAE,SAAS,EACb,MAAM,EAAE,MAAM;IAMpB,MAAM,CAAS,IAAI,EAAE,SAAS,EAAY,MAAM,EAAE,MAAM;CAG/D"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.AddressController = void 0;
|
|
16
|
+
const api_1 = require("@hed-hog/api");
|
|
17
|
+
const api_locale_1 = require("@hed-hog/api-locale");
|
|
18
|
+
const api_pagination_1 = require("@hed-hog/api-pagination");
|
|
19
|
+
const common_1 = require("@nestjs/common");
|
|
20
|
+
const address_service_1 = require("./address.service");
|
|
21
|
+
const create_dto_1 = require("./dto/create.dto");
|
|
22
|
+
const update_dto_1 = require("./dto/update.dto");
|
|
23
|
+
let AddressController = class AddressController {
|
|
24
|
+
constructor(addressService) {
|
|
25
|
+
this.addressService = addressService;
|
|
26
|
+
}
|
|
27
|
+
async list(paginationParams) {
|
|
28
|
+
return this.addressService.list(paginationParams);
|
|
29
|
+
}
|
|
30
|
+
async get(id, locale) {
|
|
31
|
+
return this.addressService.get(id, locale);
|
|
32
|
+
}
|
|
33
|
+
async create(data, locale) {
|
|
34
|
+
return this.addressService.create(data, locale);
|
|
35
|
+
}
|
|
36
|
+
async update(id, data, locale) {
|
|
37
|
+
return this.addressService.update(id, data, locale);
|
|
38
|
+
}
|
|
39
|
+
async delete(data, locale) {
|
|
40
|
+
return this.addressService.delete(data, locale);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
exports.AddressController = AddressController;
|
|
44
|
+
__decorate([
|
|
45
|
+
(0, common_1.Get)(),
|
|
46
|
+
__param(0, (0, api_pagination_1.Pagination)()),
|
|
47
|
+
__metadata("design:type", Function),
|
|
48
|
+
__metadata("design:paramtypes", [Object]),
|
|
49
|
+
__metadata("design:returntype", Promise)
|
|
50
|
+
], AddressController.prototype, "list", null);
|
|
51
|
+
__decorate([
|
|
52
|
+
(0, common_1.Get)(':id'),
|
|
53
|
+
__param(0, (0, common_1.Param)('id', common_1.ParseIntPipe)),
|
|
54
|
+
__param(1, (0, api_locale_1.Locale)()),
|
|
55
|
+
__metadata("design:type", Function),
|
|
56
|
+
__metadata("design:paramtypes", [Number, String]),
|
|
57
|
+
__metadata("design:returntype", Promise)
|
|
58
|
+
], AddressController.prototype, "get", null);
|
|
59
|
+
__decorate([
|
|
60
|
+
(0, common_1.Post)(),
|
|
61
|
+
__param(0, (0, common_1.Body)()),
|
|
62
|
+
__param(1, (0, api_locale_1.Locale)()),
|
|
63
|
+
__metadata("design:type", Function),
|
|
64
|
+
__metadata("design:paramtypes", [create_dto_1.CreateDTO, String]),
|
|
65
|
+
__metadata("design:returntype", Promise)
|
|
66
|
+
], AddressController.prototype, "create", null);
|
|
67
|
+
__decorate([
|
|
68
|
+
(0, common_1.Patch)(':id'),
|
|
69
|
+
__param(0, (0, common_1.Param)('id', common_1.ParseIntPipe)),
|
|
70
|
+
__param(1, (0, common_1.Body)()),
|
|
71
|
+
__param(2, (0, api_locale_1.Locale)()),
|
|
72
|
+
__metadata("design:type", Function),
|
|
73
|
+
__metadata("design:paramtypes", [Number, update_dto_1.UpdateDTO, String]),
|
|
74
|
+
__metadata("design:returntype", Promise)
|
|
75
|
+
], AddressController.prototype, "update", null);
|
|
76
|
+
__decorate([
|
|
77
|
+
(0, common_1.Delete)(),
|
|
78
|
+
__param(0, (0, common_1.Body)()),
|
|
79
|
+
__param(1, (0, api_locale_1.Locale)()),
|
|
80
|
+
__metadata("design:type", Function),
|
|
81
|
+
__metadata("design:paramtypes", [api_1.DeleteDTO, String]),
|
|
82
|
+
__metadata("design:returntype", Promise)
|
|
83
|
+
], AddressController.prototype, "delete", null);
|
|
84
|
+
exports.AddressController = AddressController = __decorate([
|
|
85
|
+
(0, api_1.Role)(),
|
|
86
|
+
(0, common_1.Controller)('address'),
|
|
87
|
+
__param(0, (0, common_1.Inject)((0, common_1.forwardRef)(() => address_service_1.AddressService))),
|
|
88
|
+
__metadata("design:paramtypes", [address_service_1.AddressService])
|
|
89
|
+
], AddressController);
|
|
90
|
+
//# sourceMappingURL=address.controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"address.controller.js","sourceRoot":"","sources":["../src/address.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,sCAA+C;AAC/C,oDAA6C;AAC7C,4DAAqD;AACrD,2CAWwB;AACxB,uDAAmD;AACnD,iDAA6C;AAC7C,iDAA6C;AAItC,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAC5B,YAEmB,cAA8B;QAA9B,mBAAc,GAAd,cAAc,CAAgB;IAC9C,CAAC;IAGE,AAAN,KAAK,CAAC,IAAI,CAAe,gBAAgB;QACvC,OAAO,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;IACpD,CAAC;IAGK,AAAN,KAAK,CAAC,GAAG,CAA4B,EAAU,EAAY,MA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CAAA;;qCAApB,eAAS;;+CAEnC;4BAjCU,iBAAiB;IAF7B,IAAA,UAAI,GAAE;IACN,IAAA,mBAAU,EAAC,SAAS,CAAC;IAGjB,WAAA,IAAA,eAAM,EAAC,IAAA,mBAAU,EAAC,GAAG,EAAE,CAAC,gCAAc,CAAC,CAAC,CAAA;qCACR,gCAAc;GAHtC,iBAAiB,CAkC7B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"address.module.d.ts","sourceRoot":"","sources":["../src/address.module.ts"],"names":[],"mappings":"AAQA,qBAWa,aAAa;CAAG"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.AddressModule = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
const config_1 = require("@nestjs/config");
|
|
12
|
+
const api_locale_1 = require("@hed-hog/api-locale");
|
|
13
|
+
const api_pagination_1 = require("@hed-hog/api-pagination");
|
|
14
|
+
const api_prisma_1 = require("@hed-hog/api-prisma");
|
|
15
|
+
const address_controller_1 = require("./address.controller");
|
|
16
|
+
const address_service_1 = require("./address.service");
|
|
17
|
+
let AddressModule = class AddressModule {
|
|
18
|
+
};
|
|
19
|
+
exports.AddressModule = AddressModule;
|
|
20
|
+
exports.AddressModule = AddressModule = __decorate([
|
|
21
|
+
(0, common_1.Module)({
|
|
22
|
+
imports: [
|
|
23
|
+
config_1.ConfigModule.forRoot(),
|
|
24
|
+
(0, common_1.forwardRef)(() => api_pagination_1.PaginationModule),
|
|
25
|
+
(0, common_1.forwardRef)(() => api_prisma_1.PrismaModule),
|
|
26
|
+
(0, common_1.forwardRef)(() => api_locale_1.LocaleModule)
|
|
27
|
+
],
|
|
28
|
+
controllers: [address_controller_1.AddressController],
|
|
29
|
+
providers: [address_service_1.AddressService],
|
|
30
|
+
exports: [address_service_1.AddressService]
|
|
31
|
+
})
|
|
32
|
+
], AddressModule);
|
|
33
|
+
//# sourceMappingURL=address.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"address.module.js","sourceRoot":"","sources":["../src/address.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAoD;AACpD,2CAA8C;AAC9C,oDAAmD;AACnD,4DAA2D;AAC3D,oDAAmD;AACnD,6DAAyD;AACzD,uDAAmD;AAa5C,IAAM,aAAa,GAAnB,MAAM,aAAa;CAAG,CAAA;AAAhB,sCAAa;wBAAb,aAAa;IAXzB,IAAA,eAAM,EAAC;QACN,OAAO,EAAE;YACP,qBAAY,CAAC,OAAO,EAAE;YACtB,IAAA,mBAAU,EAAC,GAAG,EAAE,CAAC,iCAAgB,CAAC;YAClC,IAAA,mBAAU,EAAC,GAAG,EAAE,CAAC,yBAAY,CAAC;YAC9B,IAAA,mBAAU,EAAC,GAAG,EAAE,CAAC,yBAAY,CAAC;SAC/B;QACD,WAAW,EAAE,CAAC,sCAAiB,CAAC;QAChC,SAAS,EAAE,CAAC,gCAAc,CAAC;QAC3B,OAAO,EAAE,CAAC,gCAAc,CAAC;KAC1B,CAAC;GACW,aAAa,CAAG"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { DeleteDTO } from '@hed-hog/api';
|
|
2
|
+
import { PaginationDTO, PaginationService } from '@hed-hog/api-pagination';
|
|
3
|
+
import { PrismaService } from '@hed-hog/api-prisma';
|
|
4
|
+
import { CreateDTO } from './dto/create.dto';
|
|
5
|
+
import { UpdateDTO } from './dto/update.dto';
|
|
6
|
+
export declare class AddressService {
|
|
7
|
+
private readonly prismaService;
|
|
8
|
+
private readonly paginationService;
|
|
9
|
+
constructor(prismaService: PrismaService, paginationService: PaginationService);
|
|
10
|
+
list(paginationParams: PaginationDTO): Promise<{
|
|
11
|
+
total: any;
|
|
12
|
+
lastPage: number;
|
|
13
|
+
page: number;
|
|
14
|
+
pageSize: number;
|
|
15
|
+
prev: number;
|
|
16
|
+
next: number;
|
|
17
|
+
data: any[];
|
|
18
|
+
}>;
|
|
19
|
+
get(id: number, locale: string): Promise<{
|
|
20
|
+
id: number;
|
|
21
|
+
person_id: number;
|
|
22
|
+
address_type_id: number;
|
|
23
|
+
country_code: string;
|
|
24
|
+
state: string;
|
|
25
|
+
city: string;
|
|
26
|
+
postal_code: string;
|
|
27
|
+
line1: string;
|
|
28
|
+
line2: string;
|
|
29
|
+
is_primary: boolean;
|
|
30
|
+
created_at: Date;
|
|
31
|
+
updated_at: Date;
|
|
32
|
+
}>;
|
|
33
|
+
create(data: CreateDTO, locale: string): Promise<any>;
|
|
34
|
+
update(id: number, data: UpdateDTO, locale: string): Promise<any>;
|
|
35
|
+
delete({ ids }: DeleteDTO, locale: string): Promise<import("@prisma/client").Prisma.BatchPayload>;
|
|
36
|
+
private clearPrimaryForType;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=address.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"address.service.d.ts","sourceRoot":"","sources":["../src/address.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC3E,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAQpD,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAE7C,qBACa,cAAc;IAGvB,OAAO,CAAC,QAAQ,CAAC,aAAa;IAE9B,OAAO,CAAC,QAAQ,CAAC,iBAAiB;gBAFjB,aAAa,EAAE,aAAa,EAE5B,iBAAiB,EAAE,iBAAiB;IAGjD,IAAI,CAAC,gBAAgB,EAAE,aAAa;;;;;;;;;IA0BpC,GAAG,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;;;;;;;;;;;;;;IAY9B,MAAM,CAAC,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM;IAiBtC,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM;IA2BlD,MAAM,CAAC,EAAE,GAAG,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM;YAoCjC,mBAAmB;CAqBlC"}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.AddressService = void 0;
|
|
16
|
+
const api_locale_1 = require("@hed-hog/api-locale");
|
|
17
|
+
const api_pagination_1 = require("@hed-hog/api-pagination");
|
|
18
|
+
const api_prisma_1 = require("@hed-hog/api-prisma");
|
|
19
|
+
const common_1 = require("@nestjs/common");
|
|
20
|
+
let AddressService = class AddressService {
|
|
21
|
+
constructor(prismaService, paginationService) {
|
|
22
|
+
this.prismaService = prismaService;
|
|
23
|
+
this.paginationService = paginationService;
|
|
24
|
+
}
|
|
25
|
+
async list(paginationParams) {
|
|
26
|
+
var _a;
|
|
27
|
+
const search = (_a = paginationParams.search) === null || _a === void 0 ? void 0 : _a.trim();
|
|
28
|
+
const orConditions = [];
|
|
29
|
+
if (search) {
|
|
30
|
+
if (!Number.isNaN(Number(search))) {
|
|
31
|
+
orConditions.push({ id: Number(search) });
|
|
32
|
+
}
|
|
33
|
+
orConditions.push({ address_type: { equals: search } }, { country_code: { contains: search, mode: 'insensitive' } }, { state: { contains: search, mode: 'insensitive' } }, { city: { contains: search, mode: 'insensitive' } }, { postal_code: { contains: search, mode: 'insensitive' } }, { line1: { contains: search, mode: 'insensitive' } }, { line2: { contains: search, mode: 'insensitive' } });
|
|
34
|
+
}
|
|
35
|
+
return this.paginationService.paginate(this.prismaService.address, paginationParams, {
|
|
36
|
+
where: orConditions.length > 0 ? { OR: orConditions } : {},
|
|
37
|
+
orderBy: { id: 'desc' }
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
async get(id, locale) {
|
|
41
|
+
const address = await this.prismaService.address.findUnique({ where: { id } });
|
|
42
|
+
if (!address) {
|
|
43
|
+
throw new common_1.NotFoundException((0, api_locale_1.getLocaleText)('addressNotFound', locale, `Address with ID ${id} not found`));
|
|
44
|
+
}
|
|
45
|
+
return address;
|
|
46
|
+
}
|
|
47
|
+
async create(data, locale) {
|
|
48
|
+
return this.prismaService.$transaction(async (tx) => {
|
|
49
|
+
var _a;
|
|
50
|
+
await this.clearPrimaryForType(tx, data.address_type, data.is_primary === true);
|
|
51
|
+
return tx.address.create({
|
|
52
|
+
data: Object.assign(Object.assign({}, data), { is_primary: (_a = data.is_primary) !== null && _a !== void 0 ? _a : false })
|
|
53
|
+
});
|
|
54
|
+
}).catch(() => {
|
|
55
|
+
throw new common_1.BadRequestException((0, api_locale_1.getLocaleText)('addressNotCreated', locale, 'Address could not be created'));
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
async update(id, data, locale) {
|
|
59
|
+
var _a, _b;
|
|
60
|
+
const existingAddress = await this.prismaService.address.findUnique({ where: { id } });
|
|
61
|
+
if (!existingAddress) {
|
|
62
|
+
throw new common_1.NotFoundException((0, api_locale_1.getLocaleText)('addressNotFound', locale, `Address with ID ${id} not found`));
|
|
63
|
+
}
|
|
64
|
+
const currentAddressType = existingAddress.address_type;
|
|
65
|
+
const nextAddressType = (_a = data.address_type) !== null && _a !== void 0 ? _a : currentAddressType;
|
|
66
|
+
const nextIsPrimary = (_b = data.is_primary) !== null && _b !== void 0 ? _b : existingAddress.is_primary;
|
|
67
|
+
return this.prismaService.$transaction(async (tx) => {
|
|
68
|
+
await this.clearPrimaryForType(tx, nextAddressType, nextIsPrimary, id);
|
|
69
|
+
return tx.address.update({
|
|
70
|
+
where: { id },
|
|
71
|
+
data
|
|
72
|
+
});
|
|
73
|
+
}).catch(() => {
|
|
74
|
+
throw new common_1.BadRequestException((0, api_locale_1.getLocaleText)('addressNotUpdated', locale, 'Address could not be updated'));
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
async delete({ ids }, locale) {
|
|
78
|
+
if (ids == undefined || ids == null) {
|
|
79
|
+
throw new common_1.BadRequestException((0, api_locale_1.getLocaleText)('deleteItemsRequired', locale, 'You must select at least one item to delete.'));
|
|
80
|
+
}
|
|
81
|
+
const existingAddresses = await this.prismaService.address.findMany({
|
|
82
|
+
where: {
|
|
83
|
+
id: {
|
|
84
|
+
in: ids
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
select: {
|
|
88
|
+
id: true
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
if (existingAddresses.length !== ids.length) {
|
|
92
|
+
const existingIds = existingAddresses.map((item) => item.id);
|
|
93
|
+
const missingIds = ids.filter((itemId) => !existingIds.includes(itemId));
|
|
94
|
+
throw new common_1.NotFoundException((0, api_locale_1.getLocaleText)('addressesNotFound', locale, `Addresses with IDs ${missingIds.join(', ')} not found`));
|
|
95
|
+
}
|
|
96
|
+
return this.prismaService.address.deleteMany({
|
|
97
|
+
where: {
|
|
98
|
+
id: {
|
|
99
|
+
in: ids
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
async clearPrimaryForType(tx, addressType, shouldClear, excludeId) {
|
|
105
|
+
if (!shouldClear) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
await tx.address.updateMany({
|
|
109
|
+
where: Object.assign({ address_type: addressType, is_primary: true }, (excludeId ? { id: { not: excludeId } } : {})),
|
|
110
|
+
data: {
|
|
111
|
+
is_primary: false
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
exports.AddressService = AddressService;
|
|
117
|
+
exports.AddressService = AddressService = __decorate([
|
|
118
|
+
(0, common_1.Injectable)(),
|
|
119
|
+
__param(0, (0, common_1.Inject)((0, common_1.forwardRef)(() => api_prisma_1.PrismaService))),
|
|
120
|
+
__param(1, (0, common_1.Inject)((0, common_1.forwardRef)(() => api_pagination_1.PaginationService))),
|
|
121
|
+
__metadata("design:paramtypes", [api_prisma_1.PrismaService,
|
|
122
|
+
api_pagination_1.PaginationService])
|
|
123
|
+
], AddressService);
|
|
124
|
+
//# sourceMappingURL=address.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"address.service.js","sourceRoot":"","sources":["../src/address.service.ts"],"names":[],"mappings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,GAAG,EAAE,SAAS,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CACjD;YACD,IAAI,EAAE;gBACJ,UAAU,EAAE,KAAK;aAClB;SACF,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AAnJY,wCAAc;yBAAd,cAAc;IAD1B,IAAA,mBAAU,GAAE;IAGR,WAAA,IAAA,eAAM,EAAC,IAAA,mBAAU,EAAC,GAAG,EAAE,CAAC,0BAAa,CAAC,CAAC,CAAA;IAEvC,WAAA,IAAA,eAAM,EAAC,IAAA,mBAAU,EAAC,GAAG,EAAE,CAAC,kCAAiB,CAAC,CAAC,CAAA;qCADZ,0BAAa;QAET,kCAAiB;GAL5C,cAAc,CAmJ1B"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export declare enum AddressTypeEnum {
|
|
2
|
+
RESIDENTIAL = "residential",
|
|
3
|
+
COMMERCIAL = "commercial",
|
|
4
|
+
CORRESPONDENCE = "correspondence",
|
|
5
|
+
ALTERNATIVE = "alternative",
|
|
6
|
+
WORK = "work",
|
|
7
|
+
BILLING = "billing",
|
|
8
|
+
SHIPPING = "shipping"
|
|
9
|
+
}
|
|
10
|
+
export declare class CreateDTO {
|
|
11
|
+
address_type: AddressTypeEnum;
|
|
12
|
+
country_code: string;
|
|
13
|
+
state: string;
|
|
14
|
+
city: string;
|
|
15
|
+
postal_code: string;
|
|
16
|
+
line1: string;
|
|
17
|
+
line2?: string;
|
|
18
|
+
is_primary?: boolean;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=create.dto.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create.dto.d.ts","sourceRoot":"","sources":["../../src/dto/create.dto.ts"],"names":[],"mappings":"AAGA,oBAAY,eAAe;IACzB,WAAW,gBAAgB;IAC3B,UAAU,eAAe;IACzB,cAAc,mBAAmB;IACjC,WAAW,gBAAgB;IAC3B,IAAI,SAAS;IACb,OAAO,YAAY;IACnB,QAAQ,aAAa;CACtB;AAED,qBAAa,SAAS;IAIpB,YAAY,EAAE,eAAe,CAAC;IAK9B,YAAY,EAAE,MAAM,CAAC;IAKrB,KAAK,EAAE,MAAM,CAAC;IAKd,IAAI,EAAE,MAAM,CAAC;IAKb,WAAW,EAAE,MAAM,CAAC;IAKpB,KAAK,EAAE,MAAM,CAAC;IAMd,KAAK,CAAC,EAAE,MAAM,CAAC;IAMf,UAAU,CAAC,EAAE,OAAO,CAAS;CAC9B"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.CreateDTO = exports.AddressTypeEnum = void 0;
|
|
13
|
+
const api_locale_1 = require("@hed-hog/api-locale");
|
|
14
|
+
const class_validator_1 = require("class-validator");
|
|
15
|
+
var AddressTypeEnum;
|
|
16
|
+
(function (AddressTypeEnum) {
|
|
17
|
+
AddressTypeEnum["RESIDENTIAL"] = "residential";
|
|
18
|
+
AddressTypeEnum["COMMERCIAL"] = "commercial";
|
|
19
|
+
AddressTypeEnum["CORRESPONDENCE"] = "correspondence";
|
|
20
|
+
AddressTypeEnum["ALTERNATIVE"] = "alternative";
|
|
21
|
+
AddressTypeEnum["WORK"] = "work";
|
|
22
|
+
AddressTypeEnum["BILLING"] = "billing";
|
|
23
|
+
AddressTypeEnum["SHIPPING"] = "shipping";
|
|
24
|
+
})(AddressTypeEnum || (exports.AddressTypeEnum = AddressTypeEnum = {}));
|
|
25
|
+
class CreateDTO {
|
|
26
|
+
constructor() {
|
|
27
|
+
this.is_primary = false;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.CreateDTO = CreateDTO;
|
|
31
|
+
__decorate([
|
|
32
|
+
(0, class_validator_1.IsEnum)(AddressTypeEnum, {
|
|
33
|
+
message: (args) => (0, api_locale_1.getLocaleText)('validation.addressTypeMustBeEnum', args.value)
|
|
34
|
+
}),
|
|
35
|
+
__metadata("design:type", String)
|
|
36
|
+
], CreateDTO.prototype, "address_type", void 0);
|
|
37
|
+
__decorate([
|
|
38
|
+
(0, class_validator_1.IsString)({
|
|
39
|
+
message: (args) => (0, api_locale_1.getLocaleText)('validation.countryCodeMustBeString', args.value)
|
|
40
|
+
}),
|
|
41
|
+
__metadata("design:type", String)
|
|
42
|
+
], CreateDTO.prototype, "country_code", void 0);
|
|
43
|
+
__decorate([
|
|
44
|
+
(0, class_validator_1.IsString)({
|
|
45
|
+
message: (args) => (0, api_locale_1.getLocaleText)('validation.stateMustBeString', args.value)
|
|
46
|
+
}),
|
|
47
|
+
__metadata("design:type", String)
|
|
48
|
+
], CreateDTO.prototype, "state", void 0);
|
|
49
|
+
__decorate([
|
|
50
|
+
(0, class_validator_1.IsString)({
|
|
51
|
+
message: (args) => (0, api_locale_1.getLocaleText)('validation.cityMustBeString', args.value)
|
|
52
|
+
}),
|
|
53
|
+
__metadata("design:type", String)
|
|
54
|
+
], CreateDTO.prototype, "city", void 0);
|
|
55
|
+
__decorate([
|
|
56
|
+
(0, class_validator_1.IsString)({
|
|
57
|
+
message: (args) => (0, api_locale_1.getLocaleText)('validation.postalCodeMustBeString', args.value)
|
|
58
|
+
}),
|
|
59
|
+
__metadata("design:type", String)
|
|
60
|
+
], CreateDTO.prototype, "postal_code", void 0);
|
|
61
|
+
__decorate([
|
|
62
|
+
(0, class_validator_1.IsString)({
|
|
63
|
+
message: (args) => (0, api_locale_1.getLocaleText)('validation.line1MustBeString', args.value)
|
|
64
|
+
}),
|
|
65
|
+
__metadata("design:type", String)
|
|
66
|
+
], CreateDTO.prototype, "line1", void 0);
|
|
67
|
+
__decorate([
|
|
68
|
+
(0, class_validator_1.IsOptional)(),
|
|
69
|
+
(0, class_validator_1.IsString)({
|
|
70
|
+
message: (args) => (0, api_locale_1.getLocaleText)('validation.line2MustBeString', args.value)
|
|
71
|
+
}),
|
|
72
|
+
__metadata("design:type", String)
|
|
73
|
+
], CreateDTO.prototype, "line2", void 0);
|
|
74
|
+
__decorate([
|
|
75
|
+
(0, class_validator_1.IsOptional)(),
|
|
76
|
+
(0, class_validator_1.IsBoolean)({
|
|
77
|
+
message: (args) => (0, api_locale_1.getLocaleText)('validation.isPrimaryMustBeBoolean', args.value)
|
|
78
|
+
}),
|
|
79
|
+
__metadata("design:type", Boolean)
|
|
80
|
+
], CreateDTO.prototype, "is_primary", void 0);
|
|
81
|
+
//# sourceMappingURL=create.dto.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create.dto.js","sourceRoot":"","sources":["../../src/dto/create.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAAoD;AACpD,qDAA0E;AAE1E,IAAY,eAQX;AARD,WAAY,eAAe;IACzB,8CAA2B,CAAA;IAC3B,4CAAyB,CAAA;IACzB,oDAAiC,CAAA;IACjC,8CAA2B,CAAA;IAC3B,gCAAa,CAAA;IACb,sCAAmB,CAAA;IACnB,wCAAqB,CAAA;AACvB,CAAC,EARW,eAAe,+BAAf,eAAe,QAQ1B;AAED,MAAa,SAAS;IAAtB;QAyCE,eAAU,GAAa,KAAK,CAAC;IAC/B,CAAC;CAAA;AA1CD,8BA0CC;AAtCC;IAHC,IAAA,wB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A,0BAAa,EAAC,mCAAmC,EAAE,IAAI,CAAC,KAAK,CAAC;KAClF,CAAC;;6CAC2B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"update.dto.d.ts","sourceRoot":"","sources":["../../src/dto/update.dto.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;;AAEzC,qBAAa,SAAU,SAAQ,cAAsB;CAAG"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UpdateDTO = void 0;
|
|
4
|
+
const mapped_types_1 = require("@nestjs/mapped-types");
|
|
5
|
+
const create_dto_1 = require("./create.dto");
|
|
6
|
+
class UpdateDTO extends (0, mapped_types_1.PartialType)(create_dto_1.CreateDTO) {
|
|
7
|
+
}
|
|
8
|
+
exports.UpdateDTO = UpdateDTO;
|
|
9
|
+
//# sourceMappingURL=update.dto.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"update.dto.js","sourceRoot":"","sources":["../../src/dto/update.dto.ts"],"names":[],"mappings":";;;AAAA,uDAAmD;AACnD,6CAAyC;AAEzC,MAAa,SAAU,SAAQ,IAAA,0BAAW,EAAC,sBAAS,CAAC;CAAG;AAAxD,8BAAwD"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./address.module"), exports);
|
|
18
|
+
__exportStar(require("./address.service"), exports);
|
|
19
|
+
__exportStar(require("./address.controller"), exports);
|
|
20
|
+
__exportStar(require("./dto/create.dto"), exports);
|
|
21
|
+
__exportStar(require("./dto/update.dto"), exports);
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mDAAiC;AACjC,oDAAkC;AAClC,uDAAqC;AACrC,mDAAiC;AACjC,mDAAiC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
- url: /address
|
|
2
|
+
method: GET
|
|
3
|
+
relations: &a1
|
|
4
|
+
role:
|
|
5
|
+
- where:
|
|
6
|
+
slug: admin
|
|
7
|
+
- where:
|
|
8
|
+
slug: admin-address
|
|
9
|
+
- url: /address
|
|
10
|
+
method: POST
|
|
11
|
+
relations: *a1
|
|
12
|
+
- url: /address/:id
|
|
13
|
+
method: GET
|
|
14
|
+
relations: *a1
|
|
15
|
+
- url: /address/:id
|
|
16
|
+
method: PATCH
|
|
17
|
+
relations: *a1
|
|
18
|
+
- url: /address
|
|
19
|
+
method: DELETE
|
|
20
|
+
relations: *a1
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
table: address
|
|
2
|
+
columns:
|
|
3
|
+
- type: pk
|
|
4
|
+
- name: address_type
|
|
5
|
+
type: enum
|
|
6
|
+
values:
|
|
7
|
+
- residential
|
|
8
|
+
- commercial
|
|
9
|
+
- correspondence
|
|
10
|
+
- alternative
|
|
11
|
+
- work
|
|
12
|
+
- billing
|
|
13
|
+
- shipping
|
|
14
|
+
- name: country_code
|
|
15
|
+
- name: state
|
|
16
|
+
- name: city
|
|
17
|
+
- name: postal_code
|
|
18
|
+
- name: line1
|
|
19
|
+
- name: line2
|
|
20
|
+
- name: is_primary
|
|
21
|
+
type: boolean
|
|
22
|
+
default: false
|
|
23
|
+
- type: created_at
|
|
24
|
+
- type: updated_at
|
|
25
|
+
indexes:
|
|
26
|
+
- columns: [address_type, is_primary]
|
|
27
|
+
unique: true
|
|
28
|
+
where: is_primary = true
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@hed-hog/address",
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"types": "dist/index.d.ts",
|
|
6
|
+
"dependencies": {
|
|
7
|
+
"@nestjs/common": "*",
|
|
8
|
+
"@nestjs/config": "^4.0.2",
|
|
9
|
+
"@nestjs/core": "^11",
|
|
10
|
+
"@nestjs/jwt": "^11",
|
|
11
|
+
"@nestjs/mapped-types": "*",
|
|
12
|
+
"@hed-hog/api": "0.0.4",
|
|
13
|
+
"@hed-hog/api-prisma": "0.0.5",
|
|
14
|
+
"@hed-hog/api-locale": "0.0.13",
|
|
15
|
+
"@hed-hog/api-pagination": "0.0.6",
|
|
16
|
+
"@hed-hog/api-types": "0.0.1"
|
|
17
|
+
},
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"import": "./dist/index.js",
|
|
21
|
+
"require": "./dist/index.js"
|
|
22
|
+
},
|
|
23
|
+
"./package.json": "./package.json"
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist",
|
|
27
|
+
"src",
|
|
28
|
+
"hedhog"
|
|
29
|
+
],
|
|
30
|
+
"scripts": {
|
|
31
|
+
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\"",
|
|
32
|
+
"prebuild": "pnpm exec ts-node ../../scripts/build-dependencies.ts libraries/address",
|
|
33
|
+
"build": "tsc --project tsconfig.production.json",
|
|
34
|
+
"patch": "pnpm exec ts-node ../../scripts/patch.ts .",
|
|
35
|
+
"prod": "pnpm run patch && pnpm run build && pnpm publish --access public --no-git-checks"
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { DeleteDTO, Role } from '@hed-hog/api';
|
|
2
|
+
import { Locale } from '@hed-hog/api-locale';
|
|
3
|
+
import { Pagination } from '@hed-hog/api-pagination';
|
|
4
|
+
import {
|
|
5
|
+
Body,
|
|
6
|
+
Controller,
|
|
7
|
+
Delete,
|
|
8
|
+
Get,
|
|
9
|
+
Inject,
|
|
10
|
+
Param,
|
|
11
|
+
ParseIntPipe,
|
|
12
|
+
Patch,
|
|
13
|
+
Post,
|
|
14
|
+
forwardRef
|
|
15
|
+
} from '@nestjs/common';
|
|
16
|
+
import { AddressService } from './address.service';
|
|
17
|
+
import { CreateDTO } from './dto/create.dto';
|
|
18
|
+
import { UpdateDTO } from './dto/update.dto';
|
|
19
|
+
|
|
20
|
+
@Role()
|
|
21
|
+
@Controller('address')
|
|
22
|
+
export class AddressController {
|
|
23
|
+
constructor(
|
|
24
|
+
@Inject(forwardRef(() => AddressService))
|
|
25
|
+
private readonly addressService: AddressService
|
|
26
|
+
) {}
|
|
27
|
+
|
|
28
|
+
@Get()
|
|
29
|
+
async list(@Pagination() paginationParams) {
|
|
30
|
+
return this.addressService.list(paginationParams);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
@Get(':id')
|
|
34
|
+
async get(@Param('id', ParseIntPipe) id: number, @Locale() locale: string) {
|
|
35
|
+
return this.addressService.get(id, locale);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
@Post()
|
|
39
|
+
async create(@Body() data: CreateDTO, @Locale() locale: string) {
|
|
40
|
+
return this.addressService.create(data, locale);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
@Patch(':id')
|
|
44
|
+
async update(
|
|
45
|
+
@Param('id', ParseIntPipe) id: number,
|
|
46
|
+
@Body() data: UpdateDTO,
|
|
47
|
+
@Locale() locale: string
|
|
48
|
+
) {
|
|
49
|
+
return this.addressService.update(id, data, locale);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
@Delete()
|
|
53
|
+
async delete(@Body() data: DeleteDTO, @Locale() locale: string) {
|
|
54
|
+
return this.addressService.delete(data, locale);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { forwardRef, Module } from '@nestjs/common';
|
|
2
|
+
import { ConfigModule } from '@nestjs/config';
|
|
3
|
+
import { LocaleModule } from '@hed-hog/api-locale';
|
|
4
|
+
import { PaginationModule } from '@hed-hog/api-pagination';
|
|
5
|
+
import { PrismaModule } from '@hed-hog/api-prisma';
|
|
6
|
+
import { AddressController } from './address.controller';
|
|
7
|
+
import { AddressService } from './address.service';
|
|
8
|
+
|
|
9
|
+
@Module({
|
|
10
|
+
imports: [
|
|
11
|
+
ConfigModule.forRoot(),
|
|
12
|
+
forwardRef(() => PaginationModule),
|
|
13
|
+
forwardRef(() => PrismaModule),
|
|
14
|
+
forwardRef(() => LocaleModule)
|
|
15
|
+
],
|
|
16
|
+
controllers: [AddressController],
|
|
17
|
+
providers: [AddressService],
|
|
18
|
+
exports: [AddressService]
|
|
19
|
+
})
|
|
20
|
+
export class AddressModule {}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { DeleteDTO } from '@hed-hog/api';
|
|
2
|
+
import { getLocaleText } from '@hed-hog/api-locale';
|
|
3
|
+
import { PaginationDTO, PaginationService } from '@hed-hog/api-pagination';
|
|
4
|
+
import { PrismaService } from '@hed-hog/api-prisma';
|
|
5
|
+
import {
|
|
6
|
+
BadRequestException,
|
|
7
|
+
Inject,
|
|
8
|
+
Injectable,
|
|
9
|
+
NotFoundException,
|
|
10
|
+
forwardRef
|
|
11
|
+
} from '@nestjs/common';
|
|
12
|
+
import { CreateDTO } from './dto/create.dto';
|
|
13
|
+
import { UpdateDTO } from './dto/update.dto';
|
|
14
|
+
|
|
15
|
+
@Injectable()
|
|
16
|
+
export class AddressService {
|
|
17
|
+
constructor(
|
|
18
|
+
@Inject(forwardRef(() => PrismaService))
|
|
19
|
+
private readonly prismaService: PrismaService,
|
|
20
|
+
@Inject(forwardRef(() => PaginationService))
|
|
21
|
+
private readonly paginationService: PaginationService
|
|
22
|
+
) {}
|
|
23
|
+
|
|
24
|
+
async list(paginationParams: PaginationDTO) {
|
|
25
|
+
const search = paginationParams.search?.trim();
|
|
26
|
+
const orConditions: any[] = [];
|
|
27
|
+
|
|
28
|
+
if (search) {
|
|
29
|
+
if (!Number.isNaN(Number(search))) {
|
|
30
|
+
orConditions.push({ id: Number(search) });
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
orConditions.push(
|
|
34
|
+
{ address_type: { equals: search } },
|
|
35
|
+
{ country_code: { contains: search, mode: 'insensitive' } },
|
|
36
|
+
{ state: { contains: search, mode: 'insensitive' } },
|
|
37
|
+
{ city: { contains: search, mode: 'insensitive' } },
|
|
38
|
+
{ postal_code: { contains: search, mode: 'insensitive' } },
|
|
39
|
+
{ line1: { contains: search, mode: 'insensitive' } },
|
|
40
|
+
{ line2: { contains: search, mode: 'insensitive' } }
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return this.paginationService.paginate(this.prismaService.address as any, paginationParams, {
|
|
45
|
+
where: orConditions.length > 0 ? { OR: orConditions } : {},
|
|
46
|
+
orderBy: { id: 'desc' }
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async get(id: number, locale: string) {
|
|
51
|
+
const address = await this.prismaService.address.findUnique({ where: { id } });
|
|
52
|
+
|
|
53
|
+
if (!address) {
|
|
54
|
+
throw new NotFoundException(
|
|
55
|
+
getLocaleText('addressNotFound', locale, `Address with ID ${id} not found`)
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return address;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
async create(data: CreateDTO, locale: string) {
|
|
63
|
+
return this.prismaService.$transaction(async (tx) => {
|
|
64
|
+
await this.clearPrimaryForType(tx, data.address_type, data.is_primary === true);
|
|
65
|
+
|
|
66
|
+
return (tx.address as any).create({
|
|
67
|
+
data: {
|
|
68
|
+
...data,
|
|
69
|
+
is_primary: data.is_primary ?? false
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}).catch(() => {
|
|
73
|
+
throw new BadRequestException(
|
|
74
|
+
getLocaleText('addressNotCreated', locale, 'Address could not be created')
|
|
75
|
+
);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async update(id: number, data: UpdateDTO, locale: string) {
|
|
80
|
+
const existingAddress = await this.prismaService.address.findUnique({ where: { id } });
|
|
81
|
+
|
|
82
|
+
if (!existingAddress) {
|
|
83
|
+
throw new NotFoundException(
|
|
84
|
+
getLocaleText('addressNotFound', locale, `Address with ID ${id} not found`)
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const currentAddressType = (existingAddress as any).address_type;
|
|
89
|
+
const nextAddressType = data.address_type ?? currentAddressType;
|
|
90
|
+
const nextIsPrimary = data.is_primary ?? existingAddress.is_primary;
|
|
91
|
+
|
|
92
|
+
return this.prismaService.$transaction(async (tx) => {
|
|
93
|
+
await this.clearPrimaryForType(tx, nextAddressType, nextIsPrimary, id);
|
|
94
|
+
|
|
95
|
+
return (tx.address as any).update({
|
|
96
|
+
where: { id },
|
|
97
|
+
data
|
|
98
|
+
});
|
|
99
|
+
}).catch(() => {
|
|
100
|
+
throw new BadRequestException(
|
|
101
|
+
getLocaleText('addressNotUpdated', locale, 'Address could not be updated')
|
|
102
|
+
);
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
async delete({ ids }: DeleteDTO, locale: string) {
|
|
107
|
+
if (ids == undefined || ids == null) {
|
|
108
|
+
throw new BadRequestException(
|
|
109
|
+
getLocaleText('deleteItemsRequired', locale, 'You must select at least one item to delete.')
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const existingAddresses = await this.prismaService.address.findMany({
|
|
114
|
+
where: {
|
|
115
|
+
id: {
|
|
116
|
+
in: ids
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
select: {
|
|
120
|
+
id: true
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
if (existingAddresses.length !== ids.length) {
|
|
125
|
+
const existingIds = existingAddresses.map((item) => item.id);
|
|
126
|
+
const missingIds = ids.filter((itemId) => !existingIds.includes(itemId));
|
|
127
|
+
|
|
128
|
+
throw new NotFoundException(
|
|
129
|
+
getLocaleText('addressesNotFound', locale, `Addresses with IDs ${missingIds.join(', ')} not found`)
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return this.prismaService.address.deleteMany({
|
|
134
|
+
where: {
|
|
135
|
+
id: {
|
|
136
|
+
in: ids
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
private async clearPrimaryForType(
|
|
143
|
+
tx: any,
|
|
144
|
+
addressType: string,
|
|
145
|
+
shouldClear: boolean,
|
|
146
|
+
excludeId?: number
|
|
147
|
+
) {
|
|
148
|
+
if (!shouldClear) {
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
await tx.address.updateMany({
|
|
153
|
+
where: {
|
|
154
|
+
address_type: addressType,
|
|
155
|
+
is_primary: true,
|
|
156
|
+
...(excludeId ? { id: { not: excludeId } } : {})
|
|
157
|
+
},
|
|
158
|
+
data: {
|
|
159
|
+
is_primary: false
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { getLocaleText } from '@hed-hog/api-locale';
|
|
2
|
+
import { IsBoolean, IsEnum, IsOptional, IsString } from 'class-validator';
|
|
3
|
+
|
|
4
|
+
export enum AddressTypeEnum {
|
|
5
|
+
RESIDENTIAL = 'residential',
|
|
6
|
+
COMMERCIAL = 'commercial',
|
|
7
|
+
CORRESPONDENCE = 'correspondence',
|
|
8
|
+
ALTERNATIVE = 'alternative',
|
|
9
|
+
WORK = 'work',
|
|
10
|
+
BILLING = 'billing',
|
|
11
|
+
SHIPPING = 'shipping'
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export class CreateDTO {
|
|
15
|
+
@IsEnum(AddressTypeEnum, {
|
|
16
|
+
message: (args) => getLocaleText('validation.addressTypeMustBeEnum', args.value)
|
|
17
|
+
})
|
|
18
|
+
address_type: AddressTypeEnum;
|
|
19
|
+
|
|
20
|
+
@IsString({
|
|
21
|
+
message: (args) => getLocaleText('validation.countryCodeMustBeString', args.value)
|
|
22
|
+
})
|
|
23
|
+
country_code: string;
|
|
24
|
+
|
|
25
|
+
@IsString({
|
|
26
|
+
message: (args) => getLocaleText('validation.stateMustBeString', args.value)
|
|
27
|
+
})
|
|
28
|
+
state: string;
|
|
29
|
+
|
|
30
|
+
@IsString({
|
|
31
|
+
message: (args) => getLocaleText('validation.cityMustBeString', args.value)
|
|
32
|
+
})
|
|
33
|
+
city: string;
|
|
34
|
+
|
|
35
|
+
@IsString({
|
|
36
|
+
message: (args) => getLocaleText('validation.postalCodeMustBeString', args.value)
|
|
37
|
+
})
|
|
38
|
+
postal_code: string;
|
|
39
|
+
|
|
40
|
+
@IsString({
|
|
41
|
+
message: (args) => getLocaleText('validation.line1MustBeString', args.value)
|
|
42
|
+
})
|
|
43
|
+
line1: string;
|
|
44
|
+
|
|
45
|
+
@IsOptional()
|
|
46
|
+
@IsString({
|
|
47
|
+
message: (args) => getLocaleText('validation.line2MustBeString', args.value)
|
|
48
|
+
})
|
|
49
|
+
line2?: string;
|
|
50
|
+
|
|
51
|
+
@IsOptional()
|
|
52
|
+
@IsBoolean({
|
|
53
|
+
message: (args) => getLocaleText('validation.isPrimaryMustBeBoolean', args.value)
|
|
54
|
+
})
|
|
55
|
+
is_primary?: boolean = false;
|
|
56
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"deleteItemsRequired": "You must select at least one item to delete.",
|
|
3
|
+
"addressNotFound": "Address not found.",
|
|
4
|
+
"addressesNotFound": "Addresses not found.",
|
|
5
|
+
"addressNotCreated": "Address could not be created.",
|
|
6
|
+
"addressNotUpdated": "Address could not be updated.",
|
|
7
|
+
"validation": {
|
|
8
|
+
"addressTypeMustBeEnum": "address_type must be a valid enum value",
|
|
9
|
+
"countryCodeMustBeString": "country_code must be a string",
|
|
10
|
+
"stateMustBeString": "state must be a string",
|
|
11
|
+
"cityMustBeString": "city must be a string",
|
|
12
|
+
"postalCodeMustBeString": "postal_code must be a string",
|
|
13
|
+
"line1MustBeString": "line1 must be a string",
|
|
14
|
+
"line2MustBeString": "line2 must be a string",
|
|
15
|
+
"isPrimaryMustBeBoolean": "is_primary must be a boolean"
|
|
16
|
+
},
|
|
17
|
+
"HomePage": {
|
|
18
|
+
"title": "Address",
|
|
19
|
+
"description": "Manage your address.",
|
|
20
|
+
"breadcrumbHome": "Home",
|
|
21
|
+
"breadcrumbCurrent": "Address"
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"deleteItemsRequired": "Voce deve selecionar pelo menos um item para excluir.",
|
|
3
|
+
"addressNotFound": "Endereco nao encontrado.",
|
|
4
|
+
"addressesNotFound": "Enderecos nao encontrados.",
|
|
5
|
+
"addressNotCreated": "Nao foi possivel criar o endereco.",
|
|
6
|
+
"addressNotUpdated": "Nao foi possivel atualizar o endereco.",
|
|
7
|
+
"validation": {
|
|
8
|
+
"addressTypeMustBeEnum": "address_type deve ser um valor de enum valido",
|
|
9
|
+
"countryCodeMustBeString": "country_code deve ser uma string",
|
|
10
|
+
"stateMustBeString": "state deve ser uma string",
|
|
11
|
+
"cityMustBeString": "city deve ser uma string",
|
|
12
|
+
"postalCodeMustBeString": "postal_code deve ser uma string",
|
|
13
|
+
"line1MustBeString": "line1 deve ser uma string",
|
|
14
|
+
"line2MustBeString": "line2 deve ser uma string",
|
|
15
|
+
"isPrimaryMustBeBoolean": "is_primary deve ser um boolean"
|
|
16
|
+
},
|
|
17
|
+
"HomePage": {
|
|
18
|
+
"title": "Address",
|
|
19
|
+
"description": "Gerencie seu address.",
|
|
20
|
+
"breadcrumbHome": "Inicio",
|
|
21
|
+
"breadcrumbCurrent": "Address"
|
|
22
|
+
}
|
|
23
|
+
}
|