@hed-hog/tag 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/dto/tag.dto.d.ts +10 -0
- package/dist/dto/tag.dto.d.ts.map +1 -0
- package/dist/dto/tag.dto.js +37 -0
- package/dist/dto/tag.dto.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/dist/tag.controller.d.ts +28 -0
- package/dist/tag.controller.d.ts.map +1 -0
- package/dist/tag.controller.js +94 -0
- package/dist/tag.controller.js.map +1 -0
- package/dist/tag.module.d.ts +3 -0
- package/dist/tag.module.d.ts.map +1 -0
- package/dist/tag.module.js +24 -0
- package/dist/tag.module.js.map +1 -0
- package/dist/tag.service.d.ts +28 -0
- package/dist/tag.service.d.ts.map +1 -0
- package/dist/tag.service.js +116 -0
- package/dist/tag.service.js.map +1 -0
- package/hedhog/data/menu.yaml +10 -0
- package/hedhog/data/route.yaml +36 -0
- package/hedhog/table/tag.yaml +9 -0
- package/package.json +37 -0
- package/src/dto/tag.dto.ts +20 -0
- package/src/index.ts +2 -0
- package/src/tag.controller.ts +60 -0
- package/src/tag.module.ts +12 -0
- package/src/tag.service.ts +119 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tag.dto.d.ts","sourceRoot":"","sources":["../../src/dto/tag.dto.ts"],"names":[],"mappings":"AAEA,oBAAY,SAAS;IACnB,MAAM,WAAW;IACjB,QAAQ,aAAa;CACtB;AAED,qBAAa,MAAM;IAGjB,IAAI,EAAE,MAAM,CAAC;IAIb,KAAK,EAAE,MAAM,CAAC;IAId,MAAM,CAAC,EAAE,SAAS,CAAC;CACpB"}
|
|
@@ -0,0 +1,37 @@
|
|
|
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.TagDTO = exports.TagStatus = void 0;
|
|
13
|
+
const class_validator_1 = require("class-validator");
|
|
14
|
+
var TagStatus;
|
|
15
|
+
(function (TagStatus) {
|
|
16
|
+
TagStatus["ACTIVE"] = "active";
|
|
17
|
+
TagStatus["INACTIVE"] = "inactive";
|
|
18
|
+
})(TagStatus || (exports.TagStatus = TagStatus = {}));
|
|
19
|
+
class TagDTO {
|
|
20
|
+
}
|
|
21
|
+
exports.TagDTO = TagDTO;
|
|
22
|
+
__decorate([
|
|
23
|
+
(0, class_validator_1.IsString)(),
|
|
24
|
+
(0, class_validator_1.IsNotEmpty)(),
|
|
25
|
+
__metadata("design:type", String)
|
|
26
|
+
], TagDTO.prototype, "slug", void 0);
|
|
27
|
+
__decorate([
|
|
28
|
+
(0, class_validator_1.IsString)(),
|
|
29
|
+
(0, class_validator_1.IsNotEmpty)(),
|
|
30
|
+
__metadata("design:type", String)
|
|
31
|
+
], TagDTO.prototype, "color", void 0);
|
|
32
|
+
__decorate([
|
|
33
|
+
(0, class_validator_1.IsEnum)(TagStatus),
|
|
34
|
+
(0, class_validator_1.IsOptional)(),
|
|
35
|
+
__metadata("design:type", String)
|
|
36
|
+
], TagDTO.prototype, "status", void 0);
|
|
37
|
+
//# sourceMappingURL=tag.dto.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tag.dto.js","sourceRoot":"","sources":["../../src/dto/tag.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qDAA2E;AAE3E,IAAY,SAGX;AAHD,WAAY,SAAS;IACnB,8BAAiB,CAAA;IACjB,kCAAqB,CAAA;AACvB,CAAC,EAHW,SAAS,yBAAT,SAAS,QAGpB;AAED,MAAa,MAAM;CAYlB;AAZD,wBAYC;AATC;IAFC,IAAA,0BAAQ,GAAE;IACV,IAAA,4BAAU,GAAE;;oCACA;AAIb;IAFC,IAAA,0BAAQ,GAAE;IACV,IAAA,4BAAU,GAAE;;qCACC;AAId;IAFC,IAAA,wBAAM,EAAC,SAAS,CAAC;IACjB,IAAA,4BAAU,GAAE;;sCACM"}
|
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,cAAc,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
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("./tag.module"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { TagDTO } from './dto/tag.dto';
|
|
2
|
+
import { TagService } from './tag.service';
|
|
3
|
+
export declare class TagController {
|
|
4
|
+
private readonly tagService;
|
|
5
|
+
constructor(tagService: TagService);
|
|
6
|
+
list(paginationParams: any): Promise<{
|
|
7
|
+
data: any;
|
|
8
|
+
total: any;
|
|
9
|
+
page: number;
|
|
10
|
+
pageSize: any;
|
|
11
|
+
prev: number;
|
|
12
|
+
next: number;
|
|
13
|
+
lastPage: number;
|
|
14
|
+
}>;
|
|
15
|
+
getTagStats(): Promise<{
|
|
16
|
+
total: any;
|
|
17
|
+
active: any;
|
|
18
|
+
inactive: any;
|
|
19
|
+
}>;
|
|
20
|
+
getById(id: number): Promise<any>;
|
|
21
|
+
create(body: TagDTO): Promise<any>;
|
|
22
|
+
update(id: number, body: Partial<TagDTO>): Promise<any>;
|
|
23
|
+
delete(id: number): Promise<{
|
|
24
|
+
deleted: boolean;
|
|
25
|
+
message: string;
|
|
26
|
+
}>;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=tag.controller.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tag.controller.d.ts","sourceRoot":"","sources":["../src/tag.controller.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,qBACa,aAAa;IACZ,OAAO,CAAC,QAAQ,CAAC,UAAU;gBAAV,UAAU,EAAE,UAAU;IAG7C,IAAI,CACM,gBAAgB,KAAA;;;;;;;;;IAM1B,WAAW;;;;;IAKX,OAAO,CAA4B,EAAE,EAAE,MAAM;IAW7C,MAAM,CAAS,IAAI,EAAE,MAAM;IAK3B,MAAM,CACiB,EAAE,EAAE,MAAM,EAC7B,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC;IAMzB,MAAM,CAA4B,EAAE,EAAE,MAAM;;;;CAGnD"}
|
|
@@ -0,0 +1,94 @@
|
|
|
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.TagController = void 0;
|
|
16
|
+
const api_pagination_1 = require("@hed-hog/api-pagination");
|
|
17
|
+
const common_1 = require("@nestjs/common");
|
|
18
|
+
const tag_dto_1 = require("./dto/tag.dto");
|
|
19
|
+
const tag_service_1 = require("./tag.service");
|
|
20
|
+
let TagController = class TagController {
|
|
21
|
+
constructor(tagService) {
|
|
22
|
+
this.tagService = tagService;
|
|
23
|
+
}
|
|
24
|
+
async list(paginationParams) {
|
|
25
|
+
return this.tagService.list(paginationParams);
|
|
26
|
+
}
|
|
27
|
+
async getTagStats() {
|
|
28
|
+
return this.tagService.getStats();
|
|
29
|
+
}
|
|
30
|
+
async getById(id) {
|
|
31
|
+
const tag = await this.tagService.getById(id);
|
|
32
|
+
if (!tag) {
|
|
33
|
+
throw new common_1.NotFoundException('Tag not found');
|
|
34
|
+
}
|
|
35
|
+
return tag;
|
|
36
|
+
}
|
|
37
|
+
async create(body) {
|
|
38
|
+
return this.tagService.create(body);
|
|
39
|
+
}
|
|
40
|
+
async update(id, body) {
|
|
41
|
+
return this.tagService.update(id, body);
|
|
42
|
+
}
|
|
43
|
+
async delete(id) {
|
|
44
|
+
return this.tagService.delete(id);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
exports.TagController = TagController;
|
|
48
|
+
__decorate([
|
|
49
|
+
(0, common_1.Get)(),
|
|
50
|
+
__param(0, (0, api_pagination_1.Pagination)()),
|
|
51
|
+
__metadata("design:type", Function),
|
|
52
|
+
__metadata("design:paramtypes", [Object]),
|
|
53
|
+
__metadata("design:returntype", Promise)
|
|
54
|
+
], TagController.prototype, "list", null);
|
|
55
|
+
__decorate([
|
|
56
|
+
(0, common_1.Get)('stats'),
|
|
57
|
+
__metadata("design:type", Function),
|
|
58
|
+
__metadata("design:paramtypes", []),
|
|
59
|
+
__metadata("design:returntype", Promise)
|
|
60
|
+
], TagController.prototype, "getTagStats", null);
|
|
61
|
+
__decorate([
|
|
62
|
+
(0, common_1.Get)(':id'),
|
|
63
|
+
__param(0, (0, common_1.Param)('id', common_1.ParseIntPipe)),
|
|
64
|
+
__metadata("design:type", Function),
|
|
65
|
+
__metadata("design:paramtypes", [Number]),
|
|
66
|
+
__metadata("design:returntype", Promise)
|
|
67
|
+
], TagController.prototype, "getById", null);
|
|
68
|
+
__decorate([
|
|
69
|
+
(0, common_1.Post)(),
|
|
70
|
+
__param(0, (0, common_1.Body)()),
|
|
71
|
+
__metadata("design:type", Function),
|
|
72
|
+
__metadata("design:paramtypes", [tag_dto_1.TagDTO]),
|
|
73
|
+
__metadata("design:returntype", Promise)
|
|
74
|
+
], TagController.prototype, "create", null);
|
|
75
|
+
__decorate([
|
|
76
|
+
(0, common_1.Patch)(':id'),
|
|
77
|
+
__param(0, (0, common_1.Param)('id', common_1.ParseIntPipe)),
|
|
78
|
+
__param(1, (0, common_1.Body)()),
|
|
79
|
+
__metadata("design:type", Function),
|
|
80
|
+
__metadata("design:paramtypes", [Number, Object]),
|
|
81
|
+
__metadata("design:returntype", Promise)
|
|
82
|
+
], TagController.prototype, "update", null);
|
|
83
|
+
__decorate([
|
|
84
|
+
(0, common_1.Delete)(':id'),
|
|
85
|
+
__param(0, (0, common_1.Param)('id', common_1.ParseIntPipe)),
|
|
86
|
+
__metadata("design:type", Function),
|
|
87
|
+
__metadata("design:paramtypes", [Number]),
|
|
88
|
+
__metadata("design:returntype", Promise)
|
|
89
|
+
], TagController.prototype, "delete", null);
|
|
90
|
+
exports.TagController = TagController = __decorate([
|
|
91
|
+
(0, common_1.Controller)('tag'),
|
|
92
|
+
__metadata("design:paramtypes", [tag_service_1.TagService])
|
|
93
|
+
], TagController);
|
|
94
|
+
//# sourceMappingURL=tag.controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tag.controller.js","sourceRoot":"","sources":["../src/tag.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,4DAAqD;AACrD,2CAUwB;AACxB,2CAAuC;AACvC,+CAA2C;AAGpC,IAAM,aAAa,GAAnB,MAAM,aAAa;IACxB,YAA6B,UAAsB;QAAtB,eAAU,GAAV,UAAU,CAAY;IAAG,CAAC;IAGjD,AAAN,KAAK,CAAC,IAAI,CACM,gBAAgB;QAE9B,OAAO,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;IAChD,CAAC;IAGK,AAAN,KAAK,CAAC,WAAW;QACf,OAAO,IAAI,CAAC,UAAU,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,CAAC;IACA,WAAA,IAAA,cAAK,EAAC,IAAI,EAAE,qBAAY,CAAC,CAAA;;;;2CAEtC;wBA1CU,aAAa;IADzB,IAAA,mBAAU,EAAC,KAAK,CAAC;qCAEyB,wBAAU;GADxC,aAAa,CA2CzB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tag.module.d.ts","sourceRoot":"","sources":["../src/tag.module.ts"],"names":[],"mappings":"AAIA,qBAMa,SAAS;CAAG"}
|
|
@@ -0,0 +1,24 @@
|
|
|
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.TagModule = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
const tag_controller_1 = require("./tag.controller");
|
|
12
|
+
const tag_service_1 = require("./tag.service");
|
|
13
|
+
let TagModule = class TagModule {
|
|
14
|
+
};
|
|
15
|
+
exports.TagModule = TagModule;
|
|
16
|
+
exports.TagModule = TagModule = __decorate([
|
|
17
|
+
(0, common_1.Module)({
|
|
18
|
+
imports: [],
|
|
19
|
+
controllers: [tag_controller_1.TagController],
|
|
20
|
+
providers: [tag_service_1.TagService],
|
|
21
|
+
exports: [tag_service_1.TagService],
|
|
22
|
+
})
|
|
23
|
+
], TagModule);
|
|
24
|
+
//# sourceMappingURL=tag.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tag.module.js","sourceRoot":"","sources":["../src/tag.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,qDAAiD;AACjD,+CAA2C;AAQpC,IAAM,SAAS,GAAf,MAAM,SAAS;CAAG,CAAA;AAAZ,8BAAS;oBAAT,SAAS;IANrB,IAAA,eAAM,EAAC;QACN,OAAO,EAAE,EAAE;QACX,WAAW,EAAE,CAAC,8BAAa,CAAC;QAC5B,SAAS,EAAE,CAAC,wBAAU,CAAC;QACvB,OAAO,EAAE,CAAC,wBAAU,CAAC;KACtB,CAAC;GACW,SAAS,CAAG"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { PrismaService } from '@hed-hog/api-prisma';
|
|
2
|
+
import { TagDTO } from './dto/tag.dto';
|
|
3
|
+
export declare class TagService {
|
|
4
|
+
private readonly prisma;
|
|
5
|
+
constructor(prisma: PrismaService);
|
|
6
|
+
list(paginationParams: any): Promise<{
|
|
7
|
+
data: any;
|
|
8
|
+
total: any;
|
|
9
|
+
page: number;
|
|
10
|
+
pageSize: any;
|
|
11
|
+
prev: number;
|
|
12
|
+
next: number;
|
|
13
|
+
lastPage: number;
|
|
14
|
+
}>;
|
|
15
|
+
getStats(): Promise<{
|
|
16
|
+
total: any;
|
|
17
|
+
active: any;
|
|
18
|
+
inactive: any;
|
|
19
|
+
}>;
|
|
20
|
+
create(body: TagDTO): Promise<any>;
|
|
21
|
+
getById(id: number): Promise<any>;
|
|
22
|
+
update(id: number, body: Partial<TagDTO>): Promise<any>;
|
|
23
|
+
delete(id: number): Promise<{
|
|
24
|
+
deleted: boolean;
|
|
25
|
+
message: string;
|
|
26
|
+
}>;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=tag.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tag.service.d.ts","sourceRoot":"","sources":["../src/tag.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAEvC,qBACa,UAAU;IACT,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAN,MAAM,EAAE,aAAa;IAE5C,IAAI,CAAC,gBAAgB,KAAA;;;;;;;;;IAuCrB,QAAQ;;;;;IAaR,MAAM,CAAC,IAAI,EAAE,MAAM;IAcnB,OAAO,CAAC,EAAE,EAAE,MAAM;IAQlB,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC;IAexC,MAAM,CAAC,EAAE,EAAE,MAAM;;;;CAqBxB"}
|
|
@@ -0,0 +1,116 @@
|
|
|
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.TagService = void 0;
|
|
13
|
+
const api_prisma_1 = require("@hed-hog/api-prisma");
|
|
14
|
+
const common_1 = require("@nestjs/common");
|
|
15
|
+
let TagService = class TagService {
|
|
16
|
+
constructor(prisma) {
|
|
17
|
+
this.prisma = prisma;
|
|
18
|
+
}
|
|
19
|
+
async list(paginationParams) {
|
|
20
|
+
var _a;
|
|
21
|
+
const searchRaw = ((_a = paginationParams.search) !== null && _a !== void 0 ? _a : '').toString().trim();
|
|
22
|
+
const hasSearch = searchRaw.length > 0;
|
|
23
|
+
const where = hasSearch
|
|
24
|
+
? {
|
|
25
|
+
OR: [
|
|
26
|
+
{ name: { contains: searchRaw, mode: 'insensitive' } },
|
|
27
|
+
{ slug: { contains: searchRaw, mode: 'insensitive' } },
|
|
28
|
+
],
|
|
29
|
+
}
|
|
30
|
+
: {};
|
|
31
|
+
const [data, total] = await Promise.all([
|
|
32
|
+
this.prisma.tag.findMany({
|
|
33
|
+
where,
|
|
34
|
+
skip: paginationParams.skip,
|
|
35
|
+
take: paginationParams.take,
|
|
36
|
+
orderBy: { id: 'desc' },
|
|
37
|
+
}),
|
|
38
|
+
this.prisma.tag.count({ where }),
|
|
39
|
+
]);
|
|
40
|
+
const pageSize = paginationParams.take;
|
|
41
|
+
const page = Math.floor(paginationParams.skip / pageSize) + 1;
|
|
42
|
+
const lastPage = Math.max(1, Math.ceil(total / pageSize));
|
|
43
|
+
const prev = page > 1 ? page - 1 : null;
|
|
44
|
+
const next = page < lastPage ? page + 1 : null;
|
|
45
|
+
return {
|
|
46
|
+
data,
|
|
47
|
+
total,
|
|
48
|
+
page,
|
|
49
|
+
pageSize,
|
|
50
|
+
prev,
|
|
51
|
+
next,
|
|
52
|
+
lastPage,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
async getStats() {
|
|
56
|
+
const [total, active, inactive] = await Promise.all([
|
|
57
|
+
this.prisma.tag.count(),
|
|
58
|
+
this.prisma.tag.count({ where: { status: 'active' } }),
|
|
59
|
+
this.prisma.tag.count({ where: { status: 'inactive' } }),
|
|
60
|
+
]);
|
|
61
|
+
return {
|
|
62
|
+
total,
|
|
63
|
+
active,
|
|
64
|
+
inactive,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
async create(body) {
|
|
68
|
+
const { slug, color, status } = body;
|
|
69
|
+
const tag = await this.prisma.tag.create({
|
|
70
|
+
data: {
|
|
71
|
+
slug,
|
|
72
|
+
color,
|
|
73
|
+
status: status || 'active',
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
return tag;
|
|
77
|
+
}
|
|
78
|
+
async getById(id) {
|
|
79
|
+
const tag = await this.prisma.tag.findUnique({
|
|
80
|
+
where: { id },
|
|
81
|
+
});
|
|
82
|
+
return tag;
|
|
83
|
+
}
|
|
84
|
+
async update(id, body) {
|
|
85
|
+
const { slug, color, status } = body;
|
|
86
|
+
const tag = await this.prisma.tag.update({
|
|
87
|
+
where: { id },
|
|
88
|
+
data: Object.assign(Object.assign(Object.assign({}, (slug && { slug })), (color && { color })), (status && { status })),
|
|
89
|
+
});
|
|
90
|
+
return tag;
|
|
91
|
+
}
|
|
92
|
+
async delete(id) {
|
|
93
|
+
const tag = await this.prisma.tag.findUnique({
|
|
94
|
+
where: { id },
|
|
95
|
+
});
|
|
96
|
+
if (!tag) {
|
|
97
|
+
return {
|
|
98
|
+
deleted: false,
|
|
99
|
+
message: 'Tag not found',
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
await this.prisma.tag.delete({
|
|
103
|
+
where: { id },
|
|
104
|
+
});
|
|
105
|
+
return {
|
|
106
|
+
deleted: true,
|
|
107
|
+
message: 'Tag deleted successfully',
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
exports.TagService = TagService;
|
|
112
|
+
exports.TagService = TagService = __decorate([
|
|
113
|
+
(0, common_1.Injectable)(),
|
|
114
|
+
__metadata("design:paramtypes", [api_prisma_1.PrismaService])
|
|
115
|
+
], TagService);
|
|
116
|
+
//# sourceMappingURL=tag.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tag.service.js","sourceRoot":"","sources":["../src/tag.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAAoD;AACpD,2CAA4C;AAIrC,IAAM,UAAU,GAAhB,MAAM,UAAU;IACrB,YAA6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|
+
role:
|
|
5
|
+
- where:
|
|
6
|
+
slug: admin
|
|
7
|
+
- url: /tag
|
|
8
|
+
method: POST
|
|
9
|
+
relations:
|
|
10
|
+
role:
|
|
11
|
+
- where:
|
|
12
|
+
slug: admin
|
|
13
|
+
- url: /tag/stats
|
|
14
|
+
method: GET
|
|
15
|
+
relations:
|
|
16
|
+
role:
|
|
17
|
+
- where:
|
|
18
|
+
slug: admin
|
|
19
|
+
- url: /tag/:id
|
|
20
|
+
method: GET
|
|
21
|
+
relations:
|
|
22
|
+
role:
|
|
23
|
+
- where:
|
|
24
|
+
slug: admin
|
|
25
|
+
- url: /tag/:id
|
|
26
|
+
method: PATCH
|
|
27
|
+
relations:
|
|
28
|
+
role:
|
|
29
|
+
- where:
|
|
30
|
+
slug: admin
|
|
31
|
+
- url: /tag
|
|
32
|
+
method: DELETE
|
|
33
|
+
relations:
|
|
34
|
+
role:
|
|
35
|
+
- where:
|
|
36
|
+
slug: admin
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@hed-hog/tag",
|
|
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-locale": "0.0.10",
|
|
13
|
+
"@hed-hog/api": "0.0.3",
|
|
14
|
+
"@hed-hog/admin": "0.0.130",
|
|
15
|
+
"@hed-hog/api-pagination": "0.0.3",
|
|
16
|
+
"@hed-hog/api-prisma": "0.0.4"
|
|
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": "npx ts-node ../../scripts/build-dependencies.ts libraries/tag",
|
|
33
|
+
"build": "tsc --project tsconfig.production.json",
|
|
34
|
+
"patch": "npx ts-node ../../scripts/patch.ts libraries/tag",
|
|
35
|
+
"prod": "pnpm run patch && pnpm run build && pnpm publish --access public --no-git-checks"
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { IsEnum, IsNotEmpty, IsOptional, IsString } from "class-validator";
|
|
2
|
+
|
|
3
|
+
export enum TagStatus {
|
|
4
|
+
ACTIVE = 'active',
|
|
5
|
+
INACTIVE = 'inactive',
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export class TagDTO {
|
|
9
|
+
@IsString()
|
|
10
|
+
@IsNotEmpty()
|
|
11
|
+
slug: string;
|
|
12
|
+
|
|
13
|
+
@IsString()
|
|
14
|
+
@IsNotEmpty()
|
|
15
|
+
color: string;
|
|
16
|
+
|
|
17
|
+
@IsEnum(TagStatus)
|
|
18
|
+
@IsOptional()
|
|
19
|
+
status?: TagStatus;
|
|
20
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { Pagination } from '@hed-hog/api-pagination';
|
|
2
|
+
import {
|
|
3
|
+
Body,
|
|
4
|
+
Controller,
|
|
5
|
+
Delete,
|
|
6
|
+
Get,
|
|
7
|
+
NotFoundException,
|
|
8
|
+
Param,
|
|
9
|
+
ParseIntPipe,
|
|
10
|
+
Patch,
|
|
11
|
+
Post,
|
|
12
|
+
} from '@nestjs/common';
|
|
13
|
+
import { TagDTO } from './dto/tag.dto';
|
|
14
|
+
import { TagService } from './tag.service';
|
|
15
|
+
|
|
16
|
+
@Controller('tag')
|
|
17
|
+
export class TagController {
|
|
18
|
+
constructor(private readonly tagService: TagService) {}
|
|
19
|
+
|
|
20
|
+
@Get()
|
|
21
|
+
async list(
|
|
22
|
+
@Pagination() paginationParams
|
|
23
|
+
) {
|
|
24
|
+
return this.tagService.list(paginationParams);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
@Get('stats')
|
|
28
|
+
async getTagStats() {
|
|
29
|
+
return this.tagService.getStats();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
@Get(':id')
|
|
33
|
+
async getById(@Param('id', ParseIntPipe) id: number) {
|
|
34
|
+
const tag = await this.tagService.getById(id);
|
|
35
|
+
|
|
36
|
+
if (!tag) {
|
|
37
|
+
throw new NotFoundException('Tag not found');
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return tag;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
@Post()
|
|
44
|
+
async create(@Body() body: TagDTO) {
|
|
45
|
+
return this.tagService.create(body);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
@Patch(':id')
|
|
49
|
+
async update(
|
|
50
|
+
@Param('id', ParseIntPipe) id: number,
|
|
51
|
+
@Body() body: Partial<TagDTO>,
|
|
52
|
+
) {
|
|
53
|
+
return this.tagService.update(id, body);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
@Delete(':id')
|
|
57
|
+
async delete(@Param('id', ParseIntPipe) id: number) {
|
|
58
|
+
return this.tagService.delete(id);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Module } from '@nestjs/common';
|
|
2
|
+
import { TagController } from './tag.controller';
|
|
3
|
+
import { TagService } from './tag.service';
|
|
4
|
+
|
|
5
|
+
@Module({
|
|
6
|
+
imports: [],
|
|
7
|
+
controllers: [TagController],
|
|
8
|
+
providers: [TagService],
|
|
9
|
+
exports: [TagService],
|
|
10
|
+
})
|
|
11
|
+
export class TagModule {}
|
|
12
|
+
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { PrismaService } from '@hed-hog/api-prisma';
|
|
2
|
+
import { Injectable } from '@nestjs/common';
|
|
3
|
+
import { TagDTO } from './dto/tag.dto';
|
|
4
|
+
|
|
5
|
+
@Injectable()
|
|
6
|
+
export class TagService {
|
|
7
|
+
constructor(private readonly prisma: PrismaService) {}
|
|
8
|
+
|
|
9
|
+
async list(paginationParams) {
|
|
10
|
+
const searchRaw = (paginationParams.search ?? '').toString().trim();
|
|
11
|
+
const hasSearch = searchRaw.length > 0;
|
|
12
|
+
const where = hasSearch
|
|
13
|
+
? {
|
|
14
|
+
OR: [
|
|
15
|
+
{ name: { contains: searchRaw, mode: 'insensitive' as const } },
|
|
16
|
+
{ slug: { contains: searchRaw, mode: 'insensitive' as const } },
|
|
17
|
+
],
|
|
18
|
+
}
|
|
19
|
+
: {};
|
|
20
|
+
|
|
21
|
+
const [data, total] = await Promise.all([
|
|
22
|
+
this.prisma.tag.findMany({
|
|
23
|
+
where,
|
|
24
|
+
skip: paginationParams.skip,
|
|
25
|
+
take: paginationParams.take,
|
|
26
|
+
orderBy: { id: 'desc' },
|
|
27
|
+
}),
|
|
28
|
+
this.prisma.tag.count({ where }),
|
|
29
|
+
]);
|
|
30
|
+
|
|
31
|
+
const pageSize = paginationParams.take;
|
|
32
|
+
const page = Math.floor(paginationParams.skip / pageSize) + 1;
|
|
33
|
+
const lastPage = Math.max(1, Math.ceil(total / pageSize));
|
|
34
|
+
const prev = page > 1 ? page - 1 : null;
|
|
35
|
+
const next = page < lastPage ? page + 1 : null;
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
data,
|
|
39
|
+
total,
|
|
40
|
+
page,
|
|
41
|
+
pageSize,
|
|
42
|
+
prev,
|
|
43
|
+
next,
|
|
44
|
+
lastPage,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async getStats() {
|
|
49
|
+
const [total, active, inactive] = await Promise.all([
|
|
50
|
+
this.prisma.tag.count(),
|
|
51
|
+
this.prisma.tag.count({ where: { status: 'active' } }),
|
|
52
|
+
this.prisma.tag.count({ where: { status: 'inactive' } }),
|
|
53
|
+
]);
|
|
54
|
+
return {
|
|
55
|
+
total,
|
|
56
|
+
active,
|
|
57
|
+
inactive,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async create(body: TagDTO) {
|
|
62
|
+
const { slug, color, status } = body;
|
|
63
|
+
|
|
64
|
+
const tag = await this.prisma.tag.create({
|
|
65
|
+
data: {
|
|
66
|
+
slug,
|
|
67
|
+
color,
|
|
68
|
+
status: status || 'active',
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
return tag;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
async getById(id: number) {
|
|
76
|
+
const tag = await this.prisma.tag.findUnique({
|
|
77
|
+
where: { id },
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
return tag;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
async update(id: number, body: Partial<TagDTO>) {
|
|
84
|
+
const { slug, color, status } = body;
|
|
85
|
+
|
|
86
|
+
const tag = await this.prisma.tag.update({
|
|
87
|
+
where: { id },
|
|
88
|
+
data: {
|
|
89
|
+
...(slug && { slug }),
|
|
90
|
+
...(color && { color }),
|
|
91
|
+
...(status && { status }),
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
return tag;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
async delete(id: number) {
|
|
99
|
+
const tag = await this.prisma.tag.findUnique({
|
|
100
|
+
where: { id },
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
if (!tag) {
|
|
104
|
+
return {
|
|
105
|
+
deleted: false,
|
|
106
|
+
message: 'Tag not found',
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
await this.prisma.tag.delete({
|
|
111
|
+
where: { id },
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
return {
|
|
115
|
+
deleted: true,
|
|
116
|
+
message: 'Tag deleted successfully',
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
}
|