-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(user): add entities for user module
- Loading branch information
Showing
4 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
"use strict"; | ||
|
||
export * from "./user.entity"; | ||
export * from "./user-profile.entity.intf"; | ||
export * from "./user-security-profile.entity.intf"; |
17 changes: 17 additions & 0 deletions
17
packages/stark-core/src/user/entities/user-profile.entity.intf.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
"use strict"; | ||
|
||
export interface StarkUserProfile { | ||
username: string; | ||
firstName: string; | ||
lastName: string; | ||
email?: string; | ||
phone?: string; | ||
language: string; | ||
referenceNumber?: string; | ||
isAnonymous?: boolean; | ||
|
||
/** | ||
* This property will contain any additional details for the user profile returned by the backend | ||
*/ | ||
custom?: object; | ||
} |
6 changes: 6 additions & 0 deletions
6
packages/stark-core/src/user/entities/user-security-profile.entity.intf.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
"use strict"; | ||
|
||
export interface StarkUserSecurityProfile { | ||
roles: string[]; | ||
workpost?: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
"use strict"; | ||
|
||
import { autoserialize } from "cerialize"; | ||
import { StarkUserProfile } from "./user-profile.entity.intf"; | ||
import { StarkUserSecurityProfile } from "./user-security-profile.entity.intf"; | ||
import { StarkResource } from "../../http/entities/index"; | ||
import { IsArray, IsBoolean, IsDefined, IsEmail, IsString, ValidateIf } from "class-validator"; | ||
|
||
export class StarkUser implements StarkUserProfile, StarkUserSecurityProfile, StarkResource { | ||
@IsDefined() | ||
@IsString() | ||
@autoserialize | ||
public uuid: string; | ||
|
||
@IsDefined() | ||
@IsString() | ||
@autoserialize | ||
public username: string; | ||
|
||
@IsDefined() | ||
@IsString() | ||
@autoserialize | ||
public firstName: string; | ||
|
||
@IsDefined() | ||
@IsString() | ||
@autoserialize | ||
public lastName: string; | ||
|
||
// @ValidateIf((user: StarkUser) => typeof user.email !== "undefined" && user.email !== null) | ||
@IsEmail() | ||
@autoserialize | ||
public email?: string; | ||
|
||
// @ValidateIf((user: StarkUser) => typeof user.phone !== "undefined" && user.phone !== null) | ||
@IsString() | ||
@autoserialize | ||
public phone?: string; | ||
|
||
// @ValidateIf((user: StarkUser) => typeof user.language !== "undefined" && user.language !== null) | ||
@IsString() | ||
@autoserialize | ||
public language: string; | ||
|
||
// @ValidateIf((user: StarkUser) => typeof user.selectedLanguage !== "undefined" && user.selectedLanguage !== null) | ||
@IsString() | ||
@autoserialize | ||
public selectedLanguage?: string; | ||
|
||
// @ValidateIf((user: StarkUser) => typeof user.referenceNumber !== "undefined" && user.referenceNumber !== null) | ||
@IsString() | ||
@autoserialize | ||
public referenceNumber?: string; | ||
|
||
@IsDefined() | ||
@IsArray() | ||
@autoserialize | ||
public roles: string[] = []; | ||
|
||
@ValidateIf((user: StarkUser) => typeof user.workpost !== "undefined" && user.workpost !== null) | ||
@IsString() | ||
@autoserialize | ||
public workpost?: string; | ||
|
||
@ValidateIf((user: StarkUser) => typeof user.isAnonymous !== "undefined" && user.isAnonymous !== null) | ||
@IsBoolean() | ||
@autoserialize | ||
public isAnonymous?: boolean; | ||
|
||
@autoserialize | ||
public custom?: object; | ||
|
||
/** | ||
* Extract the properties coming in the "details" object. | ||
* This is a callback method provided by cerialize in order to post-process the de-serialized json object. | ||
* @param instance - Instantiated object with its properties already set as defined via the serializer annotations | ||
* @param json - Raw json object retrieved from the http call | ||
* @link https://confluence.prd.nbb/display/jag/REST+-+How-to+configure+the+user+profile+resource | ||
*/ | ||
public static OnDeserialized(instance: StarkUser, json: any): void { | ||
if (json.details) { | ||
instance.language = json.details.language; | ||
instance.firstName = json.details.firstName; | ||
instance.lastName = json.details.lastName; | ||
instance.email = json.details.mail; | ||
instance.referenceNumber = json.details.referenceNumber; | ||
} | ||
} | ||
} |