Skip to content

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

feat: agency approve

Nevo David3221a022a366
diff --git a/apps/backend/src/api/routes/agencies.controller.ts b/apps/backend/src/api/routes/agencies.controller.ts
index 54f7c7773..e2849f96c 100644
--- a/apps/backend/src/api/routes/agencies.controller.ts
+++ b/apps/backend/src/api/routes/agencies.controller.ts
@@ -1,4 +1,4 @@
-import { Body, Controller, Get, Post } from '@nestjs/common';
+import { Body, Controller, Get, Param, Post } from '@nestjs/common';
import { User } from '@prisma/client';
import { ApiTags } from '@nestjs/swagger';
import { AgenciesService } from '@gitroom/nestjs-libraries/database/prisma/agencies/agencies.service';
@@ -21,4 +21,17 @@ export class AgenciesController {
) {
return this._agenciesService.createAgency(user, body);
}
+
+ @Post('/action/:action/:id')
+ async updateAgency(
+ @GetUserFromRequest() user: User,
+ @Param('action') action: string,
+ @Param('id') id: string
+ ) {
+ if (!user.isSuperAdmin) {
+ return 400;
+ }
+
+ return this._agenciesService.approveOrDecline(user.email, action, id);
+ }
}
diff --git a/libraries/nestjs-libraries/src/database/prisma/agencies/agencies.repository.ts b/libraries/nestjs-libraries/src/database/prisma/agencies/agencies.repository.ts
index 27eab628e..e0206fe45 100644
--- a/libraries/nestjs-libraries/src/database/prisma/agencies/agencies.repository.ts
+++ b/libraries/nestjs-libraries/src/database/prisma/agencies/agencies.repository.ts
@@ -44,6 +44,31 @@ export class AgenciesRepository {
});
}
+ approveOrDecline(action: string, id: string) {
+ return this._socialMediaAgencies.model.socialMediaAgency.update({
+ where: {
+ id,
+ },
+ data: {
+ approved: action === 'approve',
+ },
+ });
+ }
+
+ getAgencyById(id: string) {
+ return this._socialMediaAgencies.model.socialMediaAgency.findFirst({
+ where: {
+ id,
+ deletedAt: null,
+ approved: true,
+ },
+ include: {
+ logo: true,
+ niches: true,
+ },
+ });
+ }
+
getAgencyInformation(agency: string) {
return this._socialMediaAgencies.model.socialMediaAgency.findFirst({
where: {
diff --git a/libraries/nestjs-libraries/src/database/prisma/agencies/agencies.service.ts b/libraries/nestjs-libraries/src/database/prisma/agencies/agencies.service.ts
index 0c0cd70c7..778553624 100644
--- a/libraries/nestjs-libraries/src/database/prisma/agencies/agencies.service.ts
+++ b/libraries/nestjs-libraries/src/database/prisma/agencies/agencies.service.ts
@@ -30,6 +30,58 @@ export class AgenciesService {
return this._agenciesRepository.getAgencyInformation(agency);
}
+ async approveOrDecline(email: string, action: string, id: string) {
+ await this._agenciesRepository.approveOrDecline(action, id);
+ const agency = await this._agenciesRepository.getAgencyById(id);
+
+ if (action === 'approve') {
+ await this._emailService.sendEmail(
+ email,
+ 'Your Agency has been approved and added to Postiz πŸš€',
+ `
+<html lang="en">
+
+<head>
+ <meta charset="UTF-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <title>Your Agency has been approved and added to Postiz πŸš€</title>
+</head>
+
+<body style="font-family: Arial, sans-serif; margin: 0; padding: 0;">
+ Hi there, <br /><br />
+ Your agency ${agency?.name} has been added to Postiz!<br />
+ You can <a href="https://postiz.com/agencies/${agency?.slug}">check it here</a><br />
+ It will appear on the main agency of Postiz in the next 24 hours.<br /><br />
+</body>
+</html>`
+ );
+
+ return;
+ }
+
+ await this._emailService.sendEmail(
+ email,
+ 'Your Agency has been declined πŸ˜”',
+ `
+<html lang="en">
+
+<head>
+ <meta charset="UTF-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <title>Your Agency has been declined</title>
+</head>
+
+<body style="font-family: Arial, sans-serif; margin: 0; padding: 0;">
+ Hi there, <br /><br />
+ Your agency ${agency?.name} has been declined to Postiz!<br />
+ If you think we have made a mistake, please reply to this email and let us know
+</body>
+</html>`
+ );
+
+ return ;
+ }
+
async createAgency(user: User, body: CreateAgencyDto) {
const agency = await this._agenciesRepository.createAgency(user, body);
await this._emailService.sendEmail(
@@ -141,12 +193,12 @@ export class AgenciesService {
</tr>
<tr>
<td style="padding: 20px; text-align: center; background-color: #000;">
- <a href="https://platform.postiz.com/agencies/${
+ <a href="https://postiz.com/agencies/action/approve/${
agency.id
- }/approve" style="margin: 0 10px; text-decoration: none; color: #007bff;">To approve click here</a><br /><br /><br />
- <a href="https://platform.postiz.com/agencies/${
+ }" style="margin: 0 10px; text-decoration: none; color: #007bff;">To approve click here</a><br /><br /><br />
+ <a href="https://postiz.com/agencies/action/decline/${
agency.id
- }/decline" style="margin: 0 10px; text-decoration: none; color: #007bff;">To decline click here</a><br /><br /><br />
+ }" style="margin: 0 10px; text-decoration: none; color: #007bff;">To decline click here</a><br /><br /><br />
</td>
</tr>
<tr>