@loomcore/api 0.1.80 → 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.
@@ -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
- validationErrors = this.personService.validate(body.person);
40
- entityUtils.handleValidationResult(validationErrors, 'AuthController.registerUser');
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
  }
@@ -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: Partial<IPersonModel>): Promise<IUser | null>;
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
- const updatePersonResult = await this.personService.partialUpdateById(userContext, personId, person);
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);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loomcore/api",
3
- "version": "0.1.80",
3
+ "version": "0.1.81",
4
4
  "private": false,
5
5
  "description": "Loom Core Api - An opinionated Node.js api using Typescript, Express, and MongoDb or PostgreSQL",
6
6
  "scripts": {