@loomcore/api 0.1.79 → 0.1.81
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/controllers/auth.controller.js +4 -2
- package/dist/controllers/index.d.ts +1 -0
- package/dist/controllers/index.js +1 -0
- package/dist/controllers/persons.controller.d.ts +8 -0
- package/dist/controllers/persons.controller.js +18 -0
- package/dist/services/auth.service.d.ts +1 -1
- package/dist/services/auth.service.js +5 -2
- package/package.json +1 -1
|
@@ -36,8 +36,10 @@ export class AuthController {
|
|
|
36
36
|
const body = req.body;
|
|
37
37
|
let validationErrors = this.authService.validate(body.user);
|
|
38
38
|
entityUtils.handleValidationResult(validationErrors, 'AuthController.registerUser');
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
if (body.person) {
|
|
40
|
+
validationErrors = this.personService.validate(body.person);
|
|
41
|
+
entityUtils.handleValidationResult(validationErrors, 'AuthController.registerUser');
|
|
42
|
+
}
|
|
41
43
|
const user = await this.authService.createUser(userContext, body.user, body.person);
|
|
42
44
|
apiUtils.apiResponse(res, 201, { data: user || undefined }, UserSpec, PublicUserSpec);
|
|
43
45
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { IPersonModel } from "@loomcore/common/models";
|
|
2
|
+
import { ApiController } from "./api.controller.js";
|
|
3
|
+
import { Application } from "express";
|
|
4
|
+
import { IDatabase } from "../databases/models/index.js";
|
|
5
|
+
export declare class PersonsController extends ApiController<IPersonModel> {
|
|
6
|
+
constructor(app: Application, database: IDatabase);
|
|
7
|
+
mapRoutes(app: Application): void;
|
|
8
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ApiController } from "./api.controller.js";
|
|
2
|
+
import { isAuthorized } from "../middleware/is-authorized.js";
|
|
3
|
+
import { PersonService } from "../services/person.service.js";
|
|
4
|
+
export class PersonsController extends ApiController {
|
|
5
|
+
constructor(app, database) {
|
|
6
|
+
const personService = new PersonService(database);
|
|
7
|
+
super('persons', app, personService);
|
|
8
|
+
}
|
|
9
|
+
mapRoutes(app) {
|
|
10
|
+
super.mapRoutes(app);
|
|
11
|
+
app.get('/api/persons', isAuthorized(), this.get.bind(this));
|
|
12
|
+
app.get('/api/persons/:id', isAuthorized(), this.getById.bind(this));
|
|
13
|
+
app.post('/api/persons', isAuthorized(), this.create.bind(this));
|
|
14
|
+
app.put('/api/persons/:id', isAuthorized(), this.fullUpdateById.bind(this));
|
|
15
|
+
app.patch('/api/persons/:id', isAuthorized(), this.partialUpdateById.bind(this));
|
|
16
|
+
app.delete('/api/persons/:id', isAuthorized(), this.deleteById.bind(this));
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -23,7 +23,7 @@ export declare class AuthService extends MultiTenantApiService<IUser> {
|
|
|
23
23
|
userContext: IUserContext;
|
|
24
24
|
} | null>;
|
|
25
25
|
getUserByEmail(email: string): Promise<IUser | null>;
|
|
26
|
-
createUser(userContext: IUserContext, user: Partial<IUser>, person
|
|
26
|
+
createUser(userContext: IUserContext, user: Partial<IUser>, person?: Partial<IPersonModel>): Promise<IUser | null>;
|
|
27
27
|
requestTokenUsingRefreshToken(refreshToken: string, deviceId: string): Promise<ITokenResponse | null>;
|
|
28
28
|
changeLoggedInUsersPassword(userContext: IUserContext, body: any): Promise<UpdateResult>;
|
|
29
29
|
changePassword(userContext: IUserContext, queryObject: any, password: string): Promise<UpdateResult>;
|
|
@@ -100,13 +100,16 @@ export class AuthService extends MultiTenantApiService {
|
|
|
100
100
|
}
|
|
101
101
|
let personId = user.personId;
|
|
102
102
|
if (personId && person) {
|
|
103
|
-
|
|
103
|
+
await this.personService.partialUpdateById(userContext, personId, person);
|
|
104
104
|
}
|
|
105
|
-
if (!personId) {
|
|
105
|
+
if (!personId && person) {
|
|
106
106
|
const newPerson = await this.personService.create(userContext, person);
|
|
107
107
|
if (newPerson) {
|
|
108
108
|
personId = newPerson._id;
|
|
109
109
|
}
|
|
110
|
+
else {
|
|
111
|
+
throw new ServerError('authService.createUser: Failed to create person');
|
|
112
|
+
}
|
|
110
113
|
}
|
|
111
114
|
user.personId = personId;
|
|
112
115
|
return await this.create(userContext, user);
|