Skip to content

πŸ“¨ The ultimate agentic social media scheduling tool πŸ€–

feat: enterprise

Nevo David6d173ab7cdf0
diff --git a/apps/backend/src/api/routes/enterprise.controller.ts b/apps/backend/src/api/routes/enterprise.controller.ts
index 06abf7d6d..a594f9fe3 100644
--- a/apps/backend/src/api/routes/enterprise.controller.ts
+++ b/apps/backend/src/api/routes/enterprise.controller.ts
@@ -13,17 +13,17 @@ export class EnterpriseController {
private _organizationService: OrganizationService
) {}
- @Post('/test')
- async test(@Body('params') params: string) {
+ @Post('/create-user')
+ async createUser(@Body('params') params: string) {
try {
- const load = AuthService.verifyJWT(params) as {
- apiKey: string;
+ const { id, name, saasName, email } = AuthService.verifyJWT(params) as {
+ id: string;
+ name: string;
+ email: string;
+ saasName: string;
};
- const org = await this._organizationService.getOrgByApiKey(load.apiKey);
- return {
- connection: !!org,
- };
+ return this._organizationService.createMaxUser(id, name, saasName, email);
} catch (err) {
return { connection: false };
}
diff --git a/libraries/nestjs-libraries/src/database/prisma/organizations/organization.repository.ts b/libraries/nestjs-libraries/src/database/prisma/organizations/organization.repository.ts
index e6386e5eb..6cd72bae5 100644
--- a/libraries/nestjs-libraries/src/database/prisma/organizations/organization.repository.ts
+++ b/libraries/nestjs-libraries/src/database/prisma/organizations/organization.repository.ts
@@ -13,6 +13,44 @@ export class OrganizationRepository {
private _user: PrismaRepository<'user'>
) {}
+ createMaxUser(id: string, name: string, saasName: string, email: string) {
+ return this._organization.model.organization.create({
+ select: {
+ id: true,
+ apiKey: true,
+ },
+ data: {
+ name: name ? `${name}###${id}` : `Unnamed User###${id}`,
+ isTrailing: false,
+ subscription: {
+ create: {
+ totalChannels: 1000000,
+ subscriptionTier: 'ULTIMATE',
+ isLifetime: true,
+ period: 'YEARLY',
+ },
+ },
+ users: {
+ create: {
+ role: Role.SUPERADMIN,
+ user: {
+ create: {
+ activated: true,
+ email: email
+ ? email.split('@').join(`+${saasName}@`)
+ : `${saasName}+` + makeId(10) + '@postiz.com',
+ name: name ? `${name}###${id}` : `Unnamed User###${id}`,
+ providerName: 'LOCAL',
+ password: AuthService.hashPassword(makeId(500)),
+ timezone: 0,
+ },
+ },
+ },
+ },
+ },
+ });
+ }
+
getOrgByApiKey(api: string) {
return this._organization.model.organization.findFirst({
where: {
diff --git a/libraries/nestjs-libraries/src/database/prisma/organizations/organization.service.ts b/libraries/nestjs-libraries/src/database/prisma/organizations/organization.service.ts
index e914e5343..54ff6807b 100644
--- a/libraries/nestjs-libraries/src/database/prisma/organizations/organization.service.ts
+++ b/libraries/nestjs-libraries/src/database/prisma/organizations/organization.service.ts
@@ -32,6 +32,10 @@ export class OrganizationService {
return this._organizationRepository.getCount();
}
+ async createMaxUser(id: string, name: string, saasName: string, email: string) {
+ return this._organizationRepository.createMaxUser(id, name, saasName, email);
+ }
+
addUserToOrg(
userId: string,
id: string,