Skip to content

Commit 859ccb0

Browse files
author
dzzzzzy
committed
refactor(*): refactor user module to grpc server
1 parent e8bc091 commit 859ccb0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1262
-6189
lines changed

README.md

+1-208
Original file line numberDiff line numberDiff line change
@@ -1,208 +1 @@
1-
# Notadd User Module
2-
3-
[中文文档](./README_zh.md)
4-
5-
## Document
6-
7-
- [Design Document](./doc/design.md)
8-
9-
## Features
10-
11-
- [x] registration
12-
- [x] login
13-
- [x] Authorization and Authentication
14-
- [x] Organization Management
15-
- [x] User Management
16-
- [x] role management
17-
- [x] Information Group Management
18-
- [x] Information Item Management
19-
- [x] Global i18n support
20-
- [ ] ......
21-
22-
## Instructions for use
23-
24-
Most of the interfaces of the user module define permissions. When initializing, a super administrator user will be generated. The account number is: `sadmin`, and the password is: `sadmin`. After logging in, use `accessToken` to call `updateCurrentUserInfo`. (Update the current login user information) and change the password.
25-
26-
### Import User Module
27-
28-
Import `UserModule` in the application root module, and configure the i18n option
29-
30-
### Resource Definition
31-
32-
`@Resouce` is a general term for users to perform business operations on an entity resource.
33-
34-
Set annotations for defining resources on the `Resolver` or `Controller` class to define the current resource, such as:
35-
36-
`@Resource({ name: 'article management', identify: 'artical:manage' })`
37-
38-
`name`: The name of the resource, which is used to define the parent name of the permission. The naming method is: `resource+behavior`, such as: `related article management related api => 'article management'
39-
40-
`identity`: The unique identifier of the resource, such as: `'article management' => 'artical:manage'`
41-
42-
### Permission Definition
43-
44-
`@Permission` is a definition of a specific operation performed by the user on the current entity resource.
45-
46-
Set annotations for defining operations on the `Resolver` and `Controller` methods. The user defines the operation permissions on the current resource, such as:
47-
48-
`@Permission({ name: 'Add article', identify: 'artical:create', action: 'create', personal: true })`
49-
50-
`name`: The name of the permission, used to define the specific permission name, named: `operation + resource`, such as: `Add article in the article resource => 'Add article'
51-
52-
`identify`: The unique identifier of the permission, named: `resource: method`, such as: `'Add article' => 'artical:createArtical'`
53-
54-
`action`: permission operation type, can only be one of `create, delete, update, find`
55-
56-
The definition of permissions is inseparable from the definition of resources. The two are coexisting states. When using the permission function, the resources are defined on the class first, and then the permissions are defined on the methods that require permission control.
57-
58-
Once the resources and permissions are defined, the launcher, resources, and permissions are automatically loaded and stored in the database.
59-
60-
### Configure authorization, authentication function
61-
62-
The following is an example of the authorization and authentication function logic for the `apollo-server-express` 2.x version.
63-
64-
#### Authorization function can be automatically configured by simply importing `UserModule`
65-
66-
> app.module.ts
67-
68-
```typescript
69-
import { Module } from '@nestjs/common';
70-
import { GraphQLModule } from '@nestjs/graphql';
71-
import { TypeOrmModule } from '@nestjs/typeorm';
72-
73-
import { UserModule } from './user';
74-
75-
@Module({
76-
imports: [
77-
GraphQLModule.forRootAsync({
78-
useClass: GraphQLConfigService
79-
}),
80-
TypeOrmModule.forRoot(),
81-
UserModule.forRoot({ i18n: 'en-US' })
82-
],
83-
controllers: [],
84-
providers: [],
85-
exports: []
86-
})
87-
export class AppModule { }
88-
```
89-
90-
#### Authentication function, using the `validateUser` method of the `AuthenticationService` class in the graphql context, and passing the authenticated user to the context
91-
92-
`GraphQLJSON` is used to handle the `JSON` scalar type in graphql, you need to install `graphql-type-json` additionally, and then configure it into the resolvers option.
93-
94-
> graphql-config.service.ts
95-
96-
```typescript
97-
import { Inject, Injectable } from '@nestjs/common';
98-
import { GqlModuleOptions, GqlOptionsFactory } from '@nestjs/graphql';
99-
import * as GraphQLJSON from 'graphql-type-json';
100-
import { AuthenticationService } from '@notadd/module-user';
101-
102-
@Injectable()
103-
export class GraphQLConfigService implements GqlOptionsFactory {
104-
constructor(
105-
@Inject(AuthenticationService) private readonly authService: AuthenticationService
106-
) {}
107-
108-
createGqlOptions(): GqlModuleOptions {
109-
return {
110-
typePaths: ['./**/*.types.graphql'],
111-
resolvers: { JSON: GraphQLJSON },
112-
context: async ({ req }) => {
113-
const user = await this.authService.validateUser(req);
114-
return { user };
115-
}
116-
};
117-
}
118-
}
119-
```
120-
121-
## API Logic Description
122-
123-
User modules provide rich and flexible interfaces to various upper-layer business systems. The following describes common interface logic.
124-
125-
### Resources
126-
127-
**Query**:
128-
129-
- `findResources` queries all resource permissions and returns all resource and permission data defined by the current business system
130-
131-
### Roles
132-
133-
**Query**:
134-
135-
- `findRoles` queries all roles, returns the id and name of all roles
136-
- `findOneRoleInfo(roleId: Int!)` Query role information, return the role details of the specified id, including the permissions owned by the role and the information items they own
137-
138-
**Mutation**:
139-
140-
- `createRole(name: String!)` Add a role
141-
- `updateRole(id: Int!, name: String!)` Update the role name
142-
- `deleteRole(id: Int!)` deletes the role of the specified id
143-
- `setPermissionsToRole(roleId: Int!, permissionIds: [Int]!)` Set permissions for the role
144-
145-
### Information Groups
146-
147-
**Query**:
148-
149-
- `findAllInfoGroup` Query all information groups
150-
- `findInfoItemsByGroupId(groupId: Int!)` Query all information items under the specified information group
151-
152-
**Mutation**:
153-
154-
- `createInfoGroup(name: String!, roleId: Int!)` New information group
155-
- `deleteInfoGroup(groupId: Int!)` Delete the information group of the specified ID
156-
- `updateInfoGroup(groupId: Int!, name: String, roleId: Int)` Update the group name or the assigned role of the specified ID
157-
- `addInfoItemToInfoGroup(infoGroupId: Int!, infoItemIds: [Int]!)` Adds the specified information item to the specified information group
158-
- `deleteIntoItemFromInfoGroup(infoGroupId: Int!, infoItemIds: [Int]!)` Delete the specified information item of the specified information group
159-
160-
### Information Items
161-
162-
**Query**:
163-
164-
- `findAllInfoItem` Query all information items
165-
166-
**Mutation**:
167-
168-
- `createInfoItem(infoItemInput: InfoItemInput)` new information item
169-
- `deleteInfoItem(infoItemId: Int!)` Delete the information item of the specified ID
170-
- `updateInfoItem(updateInfoItemInput: UpdateInfoItemInput)` Updates the information item name, label, description, and type of the specified ID
171-
172-
### Organizations
173-
174-
**Query**:
175-
176-
- `findRootOrganizations` Get the root organization
177-
- `findAllOrganizations` Get all organizations
178-
- `findChildrenOrganizations(id: Int!)` Get all suborganizations under the specified organization
179-
180-
**Mutation**:
181-
182-
- `createOrganization(name: String!, parentId: Int)` creates an organization, when the parentId is empty, it represents the creation of the root organization
183-
- `updateOrganization(id: Int!, name: String!, parentId: Int!)` Update organization
184-
- `deleteOrganization(id: Int!)` delete organization
185-
- `addUsersToOrganization(id: Int!, userIds: [Int]!)` Add users to the organization
186-
- `deleteUserFromOrganization(id: Int!, userIds: [Int]!)` Delete the user under the organization
187-
188-
### Users
189-
190-
**Query**:
191-
192-
- `login(username: String!, password: String!)` Ordinary user login
193-
- `findRegisterUserInfoItem` Query the information items required for normal user registration
194-
- `findCurrentUserInfo` Query the currently logged in user information
195-
- `findUserInfoById(userId: Int!)` Query user information by ID
196-
- `findUsersInRole(roleId: Int!)` Query all user information under the specified role ID
197-
- `findUsersInOrganization(organizationId: Int!)` Get the user under the specified organization ID
198-
199-
**Mutation**:
200-
201-
- `register(registerUserInput: RegisterUserInput)` Normal user registration, the key in the parameter infoKVs is the ID of the information item (infoItem.id), and the value is the value of the information item (userInfo.value)
202-
- `createUser(createUserInput: CreateUserInput)` creates the user, the key in the parameter infoKVs is the ID of the information item (infoItem.id), and the value is the value of the information item (userInfo.value)
203-
- `addUserRole(userId: Int!, roleId: Int!)` Add a role to the user
204-
- `deleteUserRole(userId: Int!, roleId: Int!)` Delete user role
205-
- `recycleUser(userId: Int!)` delete user to recycle bin
206-
- `deleteRecycledUser(userId: Int!)` deletes users in the recycle bin
207-
- `updateUserInfo(userId: Int!, updateUserInput: UpdateUserInput)` Update user information, the key in the parameter infoKVs is the ID of the user information item value (userInfo.id), the value is the value of the information item (userInfo.value), and the relationId is The ID of the information item. When the returned key is null, you also need to pass in null.
208-
- `updateCurrentUserInfo(updateCurrentUserInput: UpdateCurrentUserInput)` Updates the current login user information. The key in the infocVs parameter is the ID of the user information item value (userInfo.id), the value is the value of the information item (userInfo.value), and the relationId is the information item. ID, when the returned key is null, you also need to pass in null
1+
# Notadd 用户服务

0 commit comments

Comments
 (0)