feat: agency approve
This commit is contained in:
parent
5f15655850
commit
3221a022a3
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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: {
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
|
|||
Loading…
Reference in New Issue