@tomei/sso
Version:
Tomei SSO Package
85 lines (75 loc) • 2.62 kB
text/typescript
import { ClassError, ObjectBase } from '@tomei/general';
import { GroupPrivilegeRepository } from './group-privilege.repository';
import { IGroupPrivilegeAttr } from '../../interfaces/group-privilege.interface';
export class GroupPrivilege extends ObjectBase {
TableName = 'sso_GroupPrivilege';
ObjectName: string;
ObjectId: string;
ObjectType = 'GroupPrivilege';
GroupPrivilegeId: number;
GroupCode: string;
SystemPrivilegeId: string;
Status: string;
private _CreatedAt: Date;
private _UpdatedAt: Date;
private _CreatedById: number;
private _UpdatedById: number;
get CreatedAt() {
return this._CreatedAt;
}
get UpdatedAt() {
return this._UpdatedAt;
}
get CreatedById() {
return this._CreatedById;
}
get UpdatedById() {
return this._UpdatedById;
}
private static _Repository = new GroupPrivilegeRepository();
private constructor(GroupPrivilegeAttr?: IGroupPrivilegeAttr) {
super();
if (GroupPrivilegeAttr) {
this.GroupPrivilegeId = GroupPrivilegeAttr.GroupPrivilegeId;
this.GroupCode = GroupPrivilegeAttr.GroupCode;
this.SystemPrivilegeId = GroupPrivilegeAttr.SystemPrivilegeId;
this.Status = GroupPrivilegeAttr.Status;
this._CreatedAt = GroupPrivilegeAttr.CreatedAt;
this._UpdatedAt = GroupPrivilegeAttr.UpdatedAt;
this._CreatedById = GroupPrivilegeAttr.CreatedById;
this._UpdatedById = GroupPrivilegeAttr.UpdatedById;
}
}
setAttributes(GroupPrivilegeAttr: IGroupPrivilegeAttr) {
this.GroupPrivilegeId = GroupPrivilegeAttr.GroupPrivilegeId;
this.GroupCode = GroupPrivilegeAttr.GroupCode;
this.SystemPrivilegeId = GroupPrivilegeAttr.SystemPrivilegeId;
this.Status = GroupPrivilegeAttr.Status;
this._CreatedAt = GroupPrivilegeAttr.CreatedAt;
this._UpdatedAt = GroupPrivilegeAttr.UpdatedAt;
this._CreatedById = GroupPrivilegeAttr.CreatedById;
this._UpdatedById = GroupPrivilegeAttr.UpdatedById;
}
public static async init(dbTransaction?: any, GroupPrivilegeId?: number) {
try {
if (GroupPrivilegeId) {
const GroupPrivilegeAttr = await this._Repository.findOne({
where: { GroupPrivilegeId },
transaction: dbTransaction,
});
if (GroupPrivilegeAttr) {
return new GroupPrivilege(GroupPrivilegeAttr.get({ plain: true }));
} else {
throw new ClassError(
'GroupPrivilege',
'GroupPrivilegeErrMsg00',
'GroupPrivilege not found',
);
}
}
return new GroupPrivilege();
} catch (error) {
throw error;
}
}
}