templates endponint
This commit is contained in:
parent
5589e5ac58
commit
2352268a07
1 changed files with 76 additions and 0 deletions
|
@ -1647,4 +1647,80 @@ App::patch('/v1/projects/:projectId/smtp')
|
||||||
$response->dynamic($project, Response::MODEL_PROJECT);
|
$response->dynamic($project, Response::MODEL_PROJECT);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
App::patch('/v1/projects/:projectId/templates/sms/:type/:locale')
|
||||||
|
->desc('Update custom SMS templates')
|
||||||
|
->groups(['api', 'projects'])
|
||||||
|
->label('scope', 'projects.write')
|
||||||
|
->label('sdk.auth', [APP_AUTH_TYPE_ADMIN])
|
||||||
|
->label('sdk.namespace', 'projects')
|
||||||
|
->label('sdk.method', 'updateSmsTemplates')
|
||||||
|
->label('sdk.response.code', Response::STATUS_CODE_OK)
|
||||||
|
->label('sdk.response.type', Response::CONTENT_TYPE_JSON)
|
||||||
|
->label('sdk.response.model', Response::MODEL_PROJECT)
|
||||||
|
->param('projectId', '', new UID(), 'Project unique ID.')
|
||||||
|
->param('type', '', new WhiteList(Config::getParam('locale-templates')['sms'] ?? []), 'Template type')
|
||||||
|
->param('locale', '', new Text(6), 'Template locale')
|
||||||
|
->param('message', '', new Text(0), 'Template message')
|
||||||
|
->inject('response')
|
||||||
|
->inject('dbForConsole')
|
||||||
|
->action(function (string $projectId, string $type, string $locale, string $message, Response $response, Database $dbForConsole) {
|
||||||
|
|
||||||
|
$project = $dbForConsole->getDocument('projects', $projectId);
|
||||||
|
|
||||||
|
if ($project->isEmpty()) {
|
||||||
|
throw new Exception(Exception::PROJECT_NOT_FOUND);
|
||||||
|
}
|
||||||
|
|
||||||
|
$templates = $project->getAttribute('templates', []);
|
||||||
|
$templates['sms.'.$type.'-'.$locale] = [
|
||||||
|
'message' => $message
|
||||||
|
];
|
||||||
|
|
||||||
|
$project = $dbForConsole->updateDocument('projects', $project->getId(), $project->setAttribute('templates', $templates));
|
||||||
|
|
||||||
|
$response->dynamic($project, Response::MODEL_PROJECT);
|
||||||
|
});
|
||||||
|
|
||||||
|
App::patch('/v1/projects/:projectId/templates/email/:type/:locale')
|
||||||
|
->desc('Update custom SMS templates')
|
||||||
|
->groups(['api', 'projects'])
|
||||||
|
->label('scope', 'projects.write')
|
||||||
|
->label('sdk.auth', [APP_AUTH_TYPE_ADMIN])
|
||||||
|
->label('sdk.namespace', 'projects')
|
||||||
|
->label('sdk.method', 'updateSmsTemplates')
|
||||||
|
->label('sdk.response.code', Response::STATUS_CODE_OK)
|
||||||
|
->label('sdk.response.type', Response::CONTENT_TYPE_JSON)
|
||||||
|
->label('sdk.response.model', Response::MODEL_PROJECT)
|
||||||
|
->param('projectId', '', new UID(), 'Project unique ID.')
|
||||||
|
->param('type', '', new WhiteList(Config::getParam('locale-templates')['sms'] ?? []), 'Template type')
|
||||||
|
->param('locale', '', new Text(6), 'Template locale')
|
||||||
|
->param('senderName', '', new Text(255), 'Name of the email sender')
|
||||||
|
->param('senderEmail', '', new Email(), 'Email of the sender')
|
||||||
|
->param('subject', '', new Text(255), 'Email Subject')
|
||||||
|
->param('message', '', new Text(0), 'Template message')
|
||||||
|
->param('replyTo', '', new Email(), 'Reply to email', true)
|
||||||
|
->inject('response')
|
||||||
|
->inject('dbForConsole')
|
||||||
|
->action(function (string $projectId, string $type, string $locale, string $senderName, string $senderEmail, string $subject, string $message, string $replyTo, Response $response, Database $dbForConsole) {
|
||||||
|
|
||||||
|
$project = $dbForConsole->getDocument('projects', $projectId);
|
||||||
|
|
||||||
|
if ($project->isEmpty()) {
|
||||||
|
throw new Exception(Exception::PROJECT_NOT_FOUND);
|
||||||
|
}
|
||||||
|
|
||||||
|
$templates = $project->getAttribute('templates', []);
|
||||||
|
$templates['email.'.$type.'-'.$locale] = [
|
||||||
|
'senderName' => $senderName,
|
||||||
|
'senderEmail' => $senderEmail,
|
||||||
|
'subject' => $subject,
|
||||||
|
'replyTo' => $replyTo,
|
||||||
|
'message' => $message
|
||||||
|
];
|
||||||
|
|
||||||
|
$project = $dbForConsole->updateDocument('projects', $project->getId(), $project->setAttribute('templates', $templates));
|
||||||
|
|
||||||
|
$response->dynamic($project, Response::MODEL_PROJECT);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue