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 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
15 | return new (P || (P = Promise))(function (resolve, reject) {
|
16 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
17 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
18 | function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
19 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
20 | });
|
21 | };
|
22 | Object.defineProperty(exports, "__esModule", { value: true });
|
23 | const common_1 = require("@nestjs/common");
|
24 | const graphql_1 = require("@nestjs/graphql");
|
25 | const http_1 = require("http");
|
26 | const exception_interceptor_1 = require("../interceptor/exception.interceptor");
|
27 | const info_group_service_1 = require("../service/info.group.service");
|
28 | let InfoGroupResolver = class InfoGroupResolver {
|
29 | constructor(infoGroupService) {
|
30 | this.infoGroupService = infoGroupService;
|
31 | }
|
32 | infoGroups() {
|
33 | return __awaiter(this, void 0, void 0, function* () {
|
34 | const infoGroups = yield this.infoGroupService.getAll();
|
35 | return { code: 200, message: "获取所有信息组成功", infoGroups };
|
36 | });
|
37 | }
|
38 | infoItems(req, body) {
|
39 | return __awaiter(this, void 0, void 0, function* () {
|
40 | const { id } = body;
|
41 | if (!id) {
|
42 | throw new common_1.HttpException("缺少参数", 400);
|
43 | }
|
44 | const infoItems = yield this.infoGroupService.getInfoItems(id);
|
45 | return { code: 200, message: "获取指定信息组的信息项成功", infoItems };
|
46 | });
|
47 | }
|
48 | createInfoGroup(req, body) {
|
49 | return __awaiter(this, void 0, void 0, function* () {
|
50 | const { name } = body;
|
51 | if (!name) {
|
52 | throw new common_1.HttpException("缺少参数", 400);
|
53 | }
|
54 | yield this.infoGroupService.createInfoGroup(name);
|
55 | return { code: 200, message: "创建信息组成功" };
|
56 | });
|
57 | }
|
58 | updateInfoGroup(req, body) {
|
59 | return __awaiter(this, void 0, void 0, function* () {
|
60 | const { id, name } = body;
|
61 | if (!id || !name) {
|
62 | throw new common_1.HttpException("缺少参数", 400);
|
63 | }
|
64 | yield this.infoGroupService.updateInfoGroup(id, name);
|
65 | return { code: 200, message: "更新信息组成功" };
|
66 | });
|
67 | }
|
68 | deleteInfoGroup(req, body) {
|
69 | return __awaiter(this, void 0, void 0, function* () {
|
70 | const { id } = body;
|
71 | if (!id) {
|
72 | throw new common_1.HttpException("缺少参数", 400);
|
73 | }
|
74 | yield this.infoGroupService.deleteInfoGroup(id);
|
75 | return { code: 200, message: "删除信息组成功" };
|
76 | });
|
77 | }
|
78 | addInfoItem(req, body) {
|
79 | return __awaiter(this, void 0, void 0, function* () {
|
80 | const { id, infoItemId } = body;
|
81 | if (!id || !infoItemId) {
|
82 | throw new common_1.HttpException("缺少参数", 400);
|
83 | }
|
84 | yield this.infoGroupService.addInfoItem(id, infoItemId);
|
85 | return { code: 200, message: "添加信息项成功" };
|
86 | });
|
87 | }
|
88 | removeInfoItem(req, body) {
|
89 | return __awaiter(this, void 0, void 0, function* () {
|
90 | const { id, infoItemId } = body;
|
91 | if (!id || !infoItemId) {
|
92 | throw new common_1.HttpException("缺少参数", 400);
|
93 | }
|
94 | yield this.infoGroupService.removeInfoItem(id, infoItemId);
|
95 | return { code: 200, message: "移除信息项成功" };
|
96 | });
|
97 | }
|
98 | };
|
99 | __decorate([
|
100 | graphql_1.Query("infoGroups"),
|
101 | __metadata("design:type", Function),
|
102 | __metadata("design:paramtypes", []),
|
103 | __metadata("design:returntype", Promise)
|
104 | ], InfoGroupResolver.prototype, "infoGroups", null);
|
105 | __decorate([
|
106 | graphql_1.Query("infoItems"),
|
107 | __metadata("design:type", Function),
|
108 | __metadata("design:paramtypes", [http_1.IncomingMessage, Object]),
|
109 | __metadata("design:returntype", Promise)
|
110 | ], InfoGroupResolver.prototype, "infoItems", null);
|
111 | __decorate([
|
112 | graphql_1.Mutation("createInfoGroup"),
|
113 | __metadata("design:type", Function),
|
114 | __metadata("design:paramtypes", [http_1.IncomingMessage, Object]),
|
115 | __metadata("design:returntype", Promise)
|
116 | ], InfoGroupResolver.prototype, "createInfoGroup", null);
|
117 | __decorate([
|
118 | graphql_1.Mutation("updateInfoGroup"),
|
119 | __metadata("design:type", Function),
|
120 | __metadata("design:paramtypes", [http_1.IncomingMessage, Object]),
|
121 | __metadata("design:returntype", Promise)
|
122 | ], InfoGroupResolver.prototype, "updateInfoGroup", null);
|
123 | __decorate([
|
124 | graphql_1.Mutation("deleteInfoGroup"),
|
125 | __metadata("design:type", Function),
|
126 | __metadata("design:paramtypes", [http_1.IncomingMessage, Object]),
|
127 | __metadata("design:returntype", Promise)
|
128 | ], InfoGroupResolver.prototype, "deleteInfoGroup", null);
|
129 | __decorate([
|
130 | graphql_1.Mutation("addInfoItem"),
|
131 | __metadata("design:type", Function),
|
132 | __metadata("design:paramtypes", [http_1.IncomingMessage, Object]),
|
133 | __metadata("design:returntype", Promise)
|
134 | ], InfoGroupResolver.prototype, "addInfoItem", null);
|
135 | __decorate([
|
136 | graphql_1.Mutation("removeInfoItem"),
|
137 | __metadata("design:type", Function),
|
138 | __metadata("design:paramtypes", [http_1.IncomingMessage, Object]),
|
139 | __metadata("design:returntype", Promise)
|
140 | ], InfoGroupResolver.prototype, "removeInfoItem", null);
|
141 | InfoGroupResolver = __decorate([
|
142 | graphql_1.Resolver("InfoGroup"),
|
143 | common_1.UseInterceptors(exception_interceptor_1.ExceptionInterceptor),
|
144 | __param(0, common_1.Inject(info_group_service_1.InfoGroupService)),
|
145 | __metadata("design:paramtypes", [info_group_service_1.InfoGroupService])
|
146 | ], InfoGroupResolver);
|
147 | exports.InfoGroupResolver = InfoGroupResolver;
|