41 lines
1.1 KiB
TypeScript
41 lines
1.1 KiB
TypeScript
|
|
import * as plugins from './plugins.js';
|
||
|
|
import { OrganizationManager } from './classes.organizationmanager.js';
|
||
|
|
import { User } from './classes.user.js';
|
||
|
|
|
||
|
|
@plugins.smartdata.Manager()
|
||
|
|
export class Organization extends plugins.smartdata.SmartDataDbDoc<
|
||
|
|
Organization,
|
||
|
|
plugins.lointReception.data.IOrganization,
|
||
|
|
OrganizationManager
|
||
|
|
> {
|
||
|
|
public static async createNewOrganizationForUser(
|
||
|
|
organizationManagerArg: OrganizationManager,
|
||
|
|
userIdArg: string,
|
||
|
|
orgNameArg: string,
|
||
|
|
slugNameArg: string,
|
||
|
|
) {
|
||
|
|
const newOrg = new Organization();
|
||
|
|
newOrg.id = plugins.smartunique.shortId();
|
||
|
|
newOrg.data = {
|
||
|
|
name: orgNameArg,
|
||
|
|
slug: slugNameArg,
|
||
|
|
billingPlanId: null,
|
||
|
|
roleIds: [],
|
||
|
|
}
|
||
|
|
await newOrg.save();
|
||
|
|
return newOrg;
|
||
|
|
}
|
||
|
|
|
||
|
|
// INSTANCE
|
||
|
|
@plugins.smartdata.unI()
|
||
|
|
id: plugins.lointReception.data.IOrganization['id'];
|
||
|
|
|
||
|
|
@plugins.smartdata.svDb()
|
||
|
|
data: plugins.lointReception.data.IOrganization['data'];
|
||
|
|
|
||
|
|
public async checkIfUserIsAdmin(userArg: User) {
|
||
|
|
const role = await this.manager.receptionRef.roleManager.getRoleForUserAndOrg(userArg, this);
|
||
|
|
return role.data.role === 'admin';
|
||
|
|
}
|
||
|
|
}
|