57 lines
1.7 KiB
TypeScript
57 lines
1.7 KiB
TypeScript
|
import { ISCIMResource, ISCIMUserEmail, ISCIMUserName } from "./Interfaces";
|
||
|
import { SCIMMeta } from "./Meta";
|
||
|
|
||
|
export class SCIMUser implements ISCIMResource {
|
||
|
public static fromPlain(plain: SCIMUser): SCIMUser {
|
||
|
const user = new SCIMUser();
|
||
|
user.id = plain.id;
|
||
|
user.externalId = plain.externalId;
|
||
|
user.userName = plain.userName;
|
||
|
user.displayName = plain.displayName;
|
||
|
user.active = plain.active;
|
||
|
user.name = plain.name;
|
||
|
user.emails = plain.emails;
|
||
|
return user;
|
||
|
}
|
||
|
|
||
|
public static fromRC(rc: IUser): SCIMUser {
|
||
|
const user = new SCIMUser();
|
||
|
user.id = rc._id;
|
||
|
user.externalId = rc._id;
|
||
|
user.setEmail(rc.emails[0].address);
|
||
|
user.displayName = rc.name;
|
||
|
user.userName = rc.username;
|
||
|
user.meta.created = new Date(rc.createdAt);
|
||
|
user.meta.lastModified = new Date(rc.createdAt);
|
||
|
if (user.active !== undefined) {
|
||
|
user.active = user.active;
|
||
|
}
|
||
|
return user;
|
||
|
}
|
||
|
|
||
|
public readonly schemas = ["urn:ietf:params:scim:schemas:core:2.0:User"];
|
||
|
public meta: SCIMMeta;
|
||
|
public id: string;
|
||
|
public externalId: string;
|
||
|
public userName: string;
|
||
|
public displayName: string;
|
||
|
public active: boolean;
|
||
|
public name: ISCIMUserName = {};
|
||
|
public emails: Array<ISCIMUserEmail> = [];
|
||
|
|
||
|
constructor() {
|
||
|
this.meta = new SCIMMeta("User", () => this.id);
|
||
|
}
|
||
|
|
||
|
public getEmail(): string {
|
||
|
if (this.emails.length > 0) {
|
||
|
return this.emails[0].value;
|
||
|
}
|
||
|
return "";
|
||
|
}
|
||
|
|
||
|
public setEmail(email: string) {
|
||
|
this.emails = [{ primary: true, value: email }];
|
||
|
}
|
||
|
}
|