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 user_service_1 = require("../service/user.service");
|
28 | let UserResolver = class UserResolver {
|
29 | constructor(userService) {
|
30 | this.userService = userService;
|
31 | }
|
32 | users() {
|
33 | return __awaiter(this, void 0, void 0, function* () {
|
34 | const users = yield this.userService.getAll();
|
35 | return { code: 200, message: "获取所有用户成功", users };
|
36 | });
|
37 | }
|
38 | freedomUsers() {
|
39 | return __awaiter(this, void 0, void 0, function* () {
|
40 | const freedomUsers = yield this.userService.getFreedomUsers();
|
41 | return { code: 200, message: "获取所有自由用户成功", freedomUsers };
|
42 | });
|
43 | }
|
44 | recycleUsers() {
|
45 | return __awaiter(this, void 0, void 0, function* () {
|
46 | const recycleUsers = yield this.userService.getRecycleUsers();
|
47 | return { code: 200, message: "获取所有回收站用户成功", recycleUsers };
|
48 | });
|
49 | }
|
50 | userInfos(req, body) {
|
51 | return __awaiter(this, void 0, void 0, function* () {
|
52 | const { id } = body;
|
53 | if (!id) {
|
54 | throw new common_1.HttpException("缺少参数", 400);
|
55 | }
|
56 | const userInfos = yield this.userService.userInfos(id);
|
57 | return { code: 200, message: "获取指定用户信息成功", userInfos };
|
58 | });
|
59 | }
|
60 | rolesInUser(req, body) {
|
61 | return __awaiter(this, void 0, void 0, function* () {
|
62 | const { id } = body;
|
63 | if (!id) {
|
64 | throw new common_1.HttpException("缺少参数", 400);
|
65 | }
|
66 | const roles = yield this.userService.roles(id);
|
67 | return { code: 200, message: "获取指定用户角色成功", roles };
|
68 | });
|
69 | }
|
70 | permissionsInUser(req, body) {
|
71 | return __awaiter(this, void 0, void 0, function* () {
|
72 | const { id } = body;
|
73 | if (!id) {
|
74 | throw new common_1.HttpException("缺少参数", 400);
|
75 | }
|
76 | const permissions = yield this.userService.permissions(id);
|
77 | return { code: 200, message: "获取指定用户角色成功", permissions };
|
78 | });
|
79 | }
|
80 | createUser(req, body) {
|
81 | return __awaiter(this, void 0, void 0, function* () {
|
82 | const { organizationId, userName, password } = body;
|
83 | if (!userName || !password) {
|
84 | throw new common_1.HttpException("缺少参数", 400);
|
85 | }
|
86 | yield this.userService.createUser(organizationId, userName, password);
|
87 | return { code: 200, message: "创建用户成功" };
|
88 | });
|
89 | }
|
90 | createUserWithUserInfo(req, body) {
|
91 | return __awaiter(this, void 0, void 0, function* () {
|
92 | const { organizationId, userName, password, groups } = body;
|
93 | if (!userName || !password) {
|
94 | throw new common_1.HttpException("缺少参数", 400);
|
95 | }
|
96 | yield this.userService.createUserWithUserInfo(req, organizationId, userName, password, groups);
|
97 | return { code: 200, message: "创建用户成功" };
|
98 | });
|
99 | }
|
100 | addUserInfo(req, body) {
|
101 | return __awaiter(this, void 0, void 0, function* () {
|
102 | const { id, groups } = body;
|
103 | if (!id) {
|
104 | throw new common_1.HttpException("缺少参数", 400);
|
105 | }
|
106 | yield this.userService.addUserInfoToUser(req, id, groups);
|
107 | return { code: 200, message: "创建用户成功" };
|
108 | });
|
109 | }
|
110 | updateUser(req, body) {
|
111 | return __awaiter(this, void 0, void 0, function* () {
|
112 | const { id, userName, password } = body;
|
113 | if (!id) {
|
114 | throw new common_1.HttpException("缺少参数", 400);
|
115 | }
|
116 | yield this.userService.updateUser(id, userName, password);
|
117 | return { code: 200, message: "更新用户成功" };
|
118 | });
|
119 | }
|
120 | bannedUser(req, body) {
|
121 | return __awaiter(this, void 0, void 0, function* () {
|
122 | const { id } = body;
|
123 | if (!id) {
|
124 | throw new common_1.HttpException("缺少参数", 400);
|
125 | }
|
126 | yield this.userService.bannedUser(id);
|
127 | return { code: 200, message: "封禁用户成功" };
|
128 | });
|
129 | }
|
130 | unBannedUser(req, body) {
|
131 | return __awaiter(this, void 0, void 0, function* () {
|
132 | const { id } = body;
|
133 | if (!id) {
|
134 | throw new common_1.HttpException("缺少参数", 400);
|
135 | }
|
136 | yield this.userService.unBannedUser(id);
|
137 | return { code: 200, message: "解封用户成功" };
|
138 | });
|
139 | }
|
140 | softDeleteUser(req, body) {
|
141 | return __awaiter(this, void 0, void 0, function* () {
|
142 | const { id } = body;
|
143 | if (!id) {
|
144 | throw new common_1.HttpException("缺少参数", 400);
|
145 | }
|
146 | yield this.userService.softDeleteUser(id);
|
147 | return { code: 200, message: "删除用户到回收站成功" };
|
148 | });
|
149 | }
|
150 | restoreUser(req, body) {
|
151 | return __awaiter(this, void 0, void 0, function* () {
|
152 | const { id } = body;
|
153 | if (!id) {
|
154 | throw new common_1.HttpException("缺少参数", 400);
|
155 | }
|
156 | yield this.userService.restoreUser(id);
|
157 | return { code: 200, message: "还原用户成功" };
|
158 | });
|
159 | }
|
160 | restoreUsers(req, body) {
|
161 | return __awaiter(this, void 0, void 0, function* () {
|
162 | const { ids } = body;
|
163 | if (!ids || ids.length === 0) {
|
164 | throw new common_1.HttpException("缺少参数", 400);
|
165 | }
|
166 | yield this.userService.restoreUsers(ids);
|
167 | return { code: 200, message: "还原多个用户成功" };
|
168 | });
|
169 | }
|
170 | deleteUser(req, body) {
|
171 | return __awaiter(this, void 0, void 0, function* () {
|
172 | const { id } = body;
|
173 | if (!id) {
|
174 | throw new common_1.HttpException("缺少参数", 400);
|
175 | }
|
176 | yield this.userService.deleteUser(id);
|
177 | return { code: 200, message: "删除用户成功" };
|
178 | });
|
179 | }
|
180 | deleteUsers(req, body) {
|
181 | return __awaiter(this, void 0, void 0, function* () {
|
182 | const { ids } = body;
|
183 | if (!ids || ids.length === 0) {
|
184 | throw new common_1.HttpException("缺少参数", 400);
|
185 | }
|
186 | yield this.userService.deleteUsers(ids);
|
187 | return { code: 200, message: "删除用户成功" };
|
188 | });
|
189 | }
|
190 | setRoles(req, body) {
|
191 | return __awaiter(this, void 0, void 0, function* () {
|
192 | const { id, roleIds } = body;
|
193 | if (!id) {
|
194 | throw new common_1.HttpException("缺少参数", 400);
|
195 | }
|
196 | yield this.userService.setRoles(id, roleIds);
|
197 | return { code: 200, message: "设置用户角色成功" };
|
198 | });
|
199 | }
|
200 | setUserOwnPermissions(req, body) {
|
201 | return __awaiter(this, void 0, void 0, function* () {
|
202 | const { id, permissionIds } = body;
|
203 | if (!id) {
|
204 | throw new common_1.HttpException("缺少参数", 400);
|
205 | }
|
206 | yield this.userService.setPermissions(id, permissionIds);
|
207 | return { code: 200, message: "设置用户权限成功" };
|
208 | });
|
209 | }
|
210 | };
|
211 | __decorate([
|
212 | graphql_1.Query("users"),
|
213 | __metadata("design:type", Function),
|
214 | __metadata("design:paramtypes", []),
|
215 | __metadata("design:returntype", Promise)
|
216 | ], UserResolver.prototype, "users", null);
|
217 | __decorate([
|
218 | graphql_1.Query("freedomUsers"),
|
219 | __metadata("design:type", Function),
|
220 | __metadata("design:paramtypes", []),
|
221 | __metadata("design:returntype", Promise)
|
222 | ], UserResolver.prototype, "freedomUsers", null);
|
223 | __decorate([
|
224 | graphql_1.Query("recycleUsers"),
|
225 | __metadata("design:type", Function),
|
226 | __metadata("design:paramtypes", []),
|
227 | __metadata("design:returntype", Promise)
|
228 | ], UserResolver.prototype, "recycleUsers", null);
|
229 | __decorate([
|
230 | graphql_1.Query("userInfos"),
|
231 | __metadata("design:type", Function),
|
232 | __metadata("design:paramtypes", [http_1.IncomingMessage, Object]),
|
233 | __metadata("design:returntype", Promise)
|
234 | ], UserResolver.prototype, "userInfos", null);
|
235 | __decorate([
|
236 | graphql_1.Query("rolesInUser"),
|
237 | __metadata("design:type", Function),
|
238 | __metadata("design:paramtypes", [http_1.IncomingMessage, Object]),
|
239 | __metadata("design:returntype", Promise)
|
240 | ], UserResolver.prototype, "rolesInUser", null);
|
241 | __decorate([
|
242 | graphql_1.Query("permissionsInUser"),
|
243 | __metadata("design:type", Function),
|
244 | __metadata("design:paramtypes", [http_1.IncomingMessage, Object]),
|
245 | __metadata("design:returntype", Promise)
|
246 | ], UserResolver.prototype, "permissionsInUser", null);
|
247 | __decorate([
|
248 | graphql_1.Mutation("createUser"),
|
249 | __metadata("design:type", Function),
|
250 | __metadata("design:paramtypes", [http_1.IncomingMessage, Object]),
|
251 | __metadata("design:returntype", Promise)
|
252 | ], UserResolver.prototype, "createUser", null);
|
253 | __decorate([
|
254 | graphql_1.Mutation("createUserWithUserInfo"),
|
255 | __metadata("design:type", Function),
|
256 | __metadata("design:paramtypes", [http_1.IncomingMessage, Object]),
|
257 | __metadata("design:returntype", Promise)
|
258 | ], UserResolver.prototype, "createUserWithUserInfo", null);
|
259 | __decorate([
|
260 | graphql_1.Mutation("addUserInfo"),
|
261 | __metadata("design:type", Function),
|
262 | __metadata("design:paramtypes", [http_1.IncomingMessage, Object]),
|
263 | __metadata("design:returntype", Promise)
|
264 | ], UserResolver.prototype, "addUserInfo", null);
|
265 | __decorate([
|
266 | graphql_1.Mutation("updateUser"),
|
267 | __metadata("design:type", Function),
|
268 | __metadata("design:paramtypes", [http_1.IncomingMessage, Object]),
|
269 | __metadata("design:returntype", Promise)
|
270 | ], UserResolver.prototype, "updateUser", null);
|
271 | __decorate([
|
272 | graphql_1.Mutation("bannedUser"),
|
273 | __metadata("design:type", Function),
|
274 | __metadata("design:paramtypes", [http_1.IncomingMessage, Object]),
|
275 | __metadata("design:returntype", Promise)
|
276 | ], UserResolver.prototype, "bannedUser", null);
|
277 | __decorate([
|
278 | graphql_1.Mutation("unBannedUser"),
|
279 | __metadata("design:type", Function),
|
280 | __metadata("design:paramtypes", [http_1.IncomingMessage, Object]),
|
281 | __metadata("design:returntype", Promise)
|
282 | ], UserResolver.prototype, "unBannedUser", null);
|
283 | __decorate([
|
284 | graphql_1.Mutation("softDeleteUser"),
|
285 | __metadata("design:type", Function),
|
286 | __metadata("design:paramtypes", [http_1.IncomingMessage, Object]),
|
287 | __metadata("design:returntype", Promise)
|
288 | ], UserResolver.prototype, "softDeleteUser", null);
|
289 | __decorate([
|
290 | graphql_1.Mutation("restoreUser"),
|
291 | __metadata("design:type", Function),
|
292 | __metadata("design:paramtypes", [http_1.IncomingMessage, Object]),
|
293 | __metadata("design:returntype", Promise)
|
294 | ], UserResolver.prototype, "restoreUser", null);
|
295 | __decorate([
|
296 | graphql_1.Mutation("restoreUsers"),
|
297 | __metadata("design:type", Function),
|
298 | __metadata("design:paramtypes", [http_1.IncomingMessage, Object]),
|
299 | __metadata("design:returntype", Promise)
|
300 | ], UserResolver.prototype, "restoreUsers", null);
|
301 | __decorate([
|
302 | graphql_1.Mutation("deleteUser"),
|
303 | __metadata("design:type", Function),
|
304 | __metadata("design:paramtypes", [http_1.IncomingMessage, Object]),
|
305 | __metadata("design:returntype", Promise)
|
306 | ], UserResolver.prototype, "deleteUser", null);
|
307 | __decorate([
|
308 | graphql_1.Mutation("deleteUsers"),
|
309 | __metadata("design:type", Function),
|
310 | __metadata("design:paramtypes", [http_1.IncomingMessage, Object]),
|
311 | __metadata("design:returntype", Promise)
|
312 | ], UserResolver.prototype, "deleteUsers", null);
|
313 | __decorate([
|
314 | graphql_1.Mutation("setRoles"),
|
315 | __metadata("design:type", Function),
|
316 | __metadata("design:paramtypes", [http_1.IncomingMessage, Object]),
|
317 | __metadata("design:returntype", Promise)
|
318 | ], UserResolver.prototype, "setRoles", null);
|
319 | __decorate([
|
320 | graphql_1.Mutation("setUserOwnPermissions"),
|
321 | __metadata("design:type", Function),
|
322 | __metadata("design:paramtypes", [http_1.IncomingMessage, Object]),
|
323 | __metadata("design:returntype", Promise)
|
324 | ], UserResolver.prototype, "setUserOwnPermissions", null);
|
325 | UserResolver = __decorate([
|
326 | graphql_1.Resolver("User"),
|
327 | common_1.UseInterceptors(exception_interceptor_1.ExceptionInterceptor),
|
328 | __param(0, common_1.Inject(user_service_1.UserService)),
|
329 | __metadata("design:paramtypes", [user_service_1.UserService])
|
330 | ], UserResolver);
|
331 | exports.UserResolver = UserResolver;
|