initial
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
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';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user