This repository has been archived on 2024-09-23. You can view files and clone it, but cannot push or open issues or pull requests.
rocketchat-scim/scim/Group.ts
2022-02-15 13:38:33 +01:00

40 lines
1.3 KiB
TypeScript

import { ISCIMGroupMember, ISCIMResource } from "./Interfaces";
import { SCIMMeta } from "./Meta";
export class SCIMGroup implements ISCIMResource {
public static fromPlain(plain: SCIMGroup): SCIMGroup {
const group = new SCIMGroup();
group.id = plain.id;
group.externalId = plain.externalId;
group.displayName = plain.displayName;
group.members = plain.members || [];
return group;
}
public static fromRC(rc: ITeam, members: Array<ITeamMember>): SCIMGroup {
const group = new SCIMGroup();
group.id = rc._id;
group.externalId = rc._id;
group.displayName = rc.name;
group.meta.created = new Date(rc.createdAt);
group.meta.lastModified = new Date(rc._updatedAt || rc.createdAt);
group.members = members.map((member) => ({
value: member.user._id,
$ref: `/Users/${member.user._id}`,
display: member.user.name,
type: "User",
}));
return group;
}
public readonly schemas = ["urn:ietf:params:scim:schemas:core:2.0:Group"];
public meta: SCIMMeta;
public id: string;
public externalId: string;
public displayName: string;
public members: Array<ISCIMGroupMember> = [];
constructor() {
this.meta = new SCIMMeta("Group", () => this.id);
}
}