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 exception_interceptor_1 = require("../interceptor/exception.interceptor");
|
24 | const common_1 = require("@nestjs/common");
|
25 | const organization_service_1 = require("../service/organization.service");
|
26 | const graphql_1 = require("@nestjs/graphql");
|
27 | let OrganizationResolver = class OrganizationResolver {
|
28 | constructor(organizationService) {
|
29 | this.organizationService = organizationService;
|
30 | }
|
31 | roots() {
|
32 | return __awaiter(this, void 0, void 0, function* () {
|
33 | const roots = yield this.organizationService.getRoots();
|
34 | return { code: 200, message: "获取所有根组织成功", roots };
|
35 | });
|
36 | }
|
37 | children(req, body) {
|
38 | return __awaiter(this, void 0, void 0, function* () {
|
39 | const { id } = body;
|
40 | if (!id) {
|
41 | throw new common_1.HttpException("缺少参数", 400);
|
42 | }
|
43 | const children = yield this.organizationService.getChildren(id);
|
44 | return { code: 200, message: "获取子组织成功", children };
|
45 | });
|
46 | }
|
47 | organizations() {
|
48 | return __awaiter(this, void 0, void 0, function* () {
|
49 | const organizations = yield this.organizationService.getAll();
|
50 | return { code: 200, message: "获取所有组织成功", organizations: [] };
|
51 | });
|
52 | }
|
53 | createOrganization(req, body) {
|
54 | return __awaiter(this, void 0, void 0, function* () {
|
55 | const { name, parentId } = body;
|
56 | if (!name) {
|
57 | throw new common_1.HttpException("缺少参数", 400);
|
58 | }
|
59 | if (parentId && !Number.isInteger(parentId)) {
|
60 | throw new common_1.HttpException("父组织Id不是整数", 401);
|
61 | }
|
62 | yield this.organizationService.createOrganization(name, parentId);
|
63 | return { code: 200, message: "创建组织成功" };
|
64 | });
|
65 | }
|
66 | updateOrganization(req, body) {
|
67 | return __awaiter(this, void 0, void 0, function* () {
|
68 | const { id, name, parentId } = body;
|
69 | if (!id || !name) {
|
70 | throw new common_1.HttpException("缺少参数", 400);
|
71 | }
|
72 | if (parentId && !Number.isInteger(parentId)) {
|
73 | throw new common_1.HttpException("父组织Id不是整数", 401);
|
74 | }
|
75 | yield this.organizationService.updateOrganization(id, name, parentId);
|
76 | return { code: 200, message: "更新组织成功" };
|
77 | });
|
78 | }
|
79 | deleteOrganization(req, body) {
|
80 | return __awaiter(this, void 0, void 0, function* () {
|
81 | const { id } = body;
|
82 | if (!id) {
|
83 | throw new common_1.HttpException("缺少参数", 400);
|
84 | }
|
85 | yield this.organizationService.deleteOrganization(id);
|
86 | return { code: 200, message: "删除组织成功" };
|
87 | });
|
88 | }
|
89 | usersInOrganization(req, body) {
|
90 | return __awaiter(this, void 0, void 0, function* () {
|
91 | const { id } = body;
|
92 | if (!id) {
|
93 | throw new common_1.HttpException("缺少参数", 400);
|
94 | }
|
95 | const users = yield this.organizationService.getUsersInOrganization(id);
|
96 | return { code: 200, message: "获取组织用户成功", users };
|
97 | });
|
98 | }
|
99 | addUserToOrganization(req, body) {
|
100 | return __awaiter(this, void 0, void 0, function* () {
|
101 | const { id, userId } = body;
|
102 | if (!id || !userId) {
|
103 | throw new common_1.HttpException("缺少参数", 400);
|
104 | }
|
105 | yield this.organizationService.addUserToOrganization(id, userId);
|
106 | return { code: 200, message: "向组织添加用户成功", };
|
107 | });
|
108 | }
|
109 | addUsersToOrganization(req, body) {
|
110 | return __awaiter(this, void 0, void 0, function* () {
|
111 | const { id, userIds } = body;
|
112 | if (!id || !userIds || userIds.length === 0) {
|
113 | throw new common_1.HttpException("缺少参数", 400);
|
114 | }
|
115 | yield this.organizationService.addUsersToOrganization(id, userIds);
|
116 | return { code: 200, message: "向组织添加多个用户成功" };
|
117 | });
|
118 | }
|
119 | removeUserFromOrganization(req, body) {
|
120 | return __awaiter(this, void 0, void 0, function* () {
|
121 | const { id, userId } = body;
|
122 | if (!id || !userId) {
|
123 | throw new common_1.HttpException("缺少参数", 400);
|
124 | }
|
125 | yield this.organizationService.removeUserFromOrganization(id, userId);
|
126 | return { code: 200, message: "从组织移除用户成功" };
|
127 | });
|
128 | }
|
129 | removeUsersFromOrganization(req, body) {
|
130 | return __awaiter(this, void 0, void 0, function* () {
|
131 | const { id, userIds } = body;
|
132 | if (!id || !userIds || userIds.length === 0) {
|
133 | throw new common_1.HttpException("缺少参数", 400);
|
134 | }
|
135 | yield this.organizationService.removeUsersFromOrganization(id, userIds);
|
136 | return { code: 200, message: "从组织移除多个用户成功" };
|
137 | });
|
138 | }
|
139 | };
|
140 | __decorate([
|
141 | graphql_1.Query("roots"),
|
142 | __metadata("design:type", Function),
|
143 | __metadata("design:paramtypes", []),
|
144 | __metadata("design:returntype", Promise)
|
145 | ], OrganizationResolver.prototype, "roots", null);
|
146 | __decorate([
|
147 | graphql_1.Query("children"),
|
148 | __metadata("design:type", Function),
|
149 | __metadata("design:paramtypes", [Object, Object]),
|
150 | __metadata("design:returntype", Promise)
|
151 | ], OrganizationResolver.prototype, "children", null);
|
152 | __decorate([
|
153 | graphql_1.Query("organizations"),
|
154 | __metadata("design:type", Function),
|
155 | __metadata("design:paramtypes", []),
|
156 | __metadata("design:returntype", Promise)
|
157 | ], OrganizationResolver.prototype, "organizations", null);
|
158 | __decorate([
|
159 | graphql_1.Mutation("createOrganization"),
|
160 | __metadata("design:type", Function),
|
161 | __metadata("design:paramtypes", [Object, Object]),
|
162 | __metadata("design:returntype", Promise)
|
163 | ], OrganizationResolver.prototype, "createOrganization", null);
|
164 | __decorate([
|
165 | graphql_1.Mutation("updateOrganization"),
|
166 | __metadata("design:type", Function),
|
167 | __metadata("design:paramtypes", [Object, Object]),
|
168 | __metadata("design:returntype", Promise)
|
169 | ], OrganizationResolver.prototype, "updateOrganization", null);
|
170 | __decorate([
|
171 | graphql_1.Mutation("deleteOrganization"),
|
172 | __metadata("design:type", Function),
|
173 | __metadata("design:paramtypes", [Object, Object]),
|
174 | __metadata("design:returntype", Promise)
|
175 | ], OrganizationResolver.prototype, "deleteOrganization", null);
|
176 | __decorate([
|
177 | graphql_1.Query("usersInOrganization"),
|
178 | __metadata("design:type", Function),
|
179 | __metadata("design:paramtypes", [Object, Object]),
|
180 | __metadata("design:returntype", Promise)
|
181 | ], OrganizationResolver.prototype, "usersInOrganization", null);
|
182 | __decorate([
|
183 | graphql_1.Mutation("addUserToOrganization"),
|
184 | __metadata("design:type", Function),
|
185 | __metadata("design:paramtypes", [Object, Object]),
|
186 | __metadata("design:returntype", Promise)
|
187 | ], OrganizationResolver.prototype, "addUserToOrganization", null);
|
188 | __decorate([
|
189 | graphql_1.Mutation("addUsersToOrganization"),
|
190 | __metadata("design:type", Function),
|
191 | __metadata("design:paramtypes", [Object, Object]),
|
192 | __metadata("design:returntype", Promise)
|
193 | ], OrganizationResolver.prototype, "addUsersToOrganization", null);
|
194 | __decorate([
|
195 | graphql_1.Mutation("removeUserFromOrganization"),
|
196 | __metadata("design:type", Function),
|
197 | __metadata("design:paramtypes", [Object, Object]),
|
198 | __metadata("design:returntype", Promise)
|
199 | ], OrganizationResolver.prototype, "removeUserFromOrganization", null);
|
200 | __decorate([
|
201 | graphql_1.Mutation("removeUsersFromOrganization"),
|
202 | __metadata("design:type", Function),
|
203 | __metadata("design:paramtypes", [Object, Object]),
|
204 | __metadata("design:returntype", Promise)
|
205 | ], OrganizationResolver.prototype, "removeUsersFromOrganization", null);
|
206 | OrganizationResolver = __decorate([
|
207 | graphql_1.Resolver("Organization"),
|
208 | common_1.UseInterceptors(exception_interceptor_1.ExceptionInterceptor),
|
209 | __param(0, common_1.Inject(organization_service_1.OrganizationService)),
|
210 | __metadata("design:paramtypes", [organization_service_1.OrganizationService])
|
211 | ], OrganizationResolver);
|
212 | exports.OrganizationResolver = OrganizationResolver;
|
213 |
|
214 |
|