feat: implement template editing functionality and revert approved templates to draft status

This commit is contained in:
hamed
2026-06-19 20:48:44 +03:30
parent fa332f7fa1
commit b686cd1e7d
3 changed files with 67 additions and 6 deletions
+7 -3
View File
@@ -204,11 +204,15 @@ class SmsController extends BaseController
return $this->error(ErrorCodes::ERR_NOT_FOUND_001, 'تمپلیت یافت نشد', 404);
}
if ($template->getStatus() === SmsTemplate::STATUS_APPROVED) {
return $this->error(ErrorCodes::ERR_SMS_003, ErrorCodes::message(ErrorCodes::ERR_SMS_003), 422);
$data = json_decode($request->getContent(), true) ?? [];
// ویرایش محتوای یک قالبِ تأییدشده، آن را به پیش‌نویس برمی‌گرداند تا متن جدید
// دوباره تأیید/ارسال شود (متن قبلی با سرویس‌دهنده هماهنگ بوده).
$contentChanged = array_key_exists('name', $data) || array_key_exists('body', $data) || array_key_exists('variables', $data);
if ($template->getStatus() === SmsTemplate::STATUS_APPROVED && $contentChanged) {
$template->revertToDraft();
}
$data = json_decode($request->getContent(), true) ?? [];
if (array_key_exists('name', $data)) $template->setName($data['name']);
if (array_key_exists('body', $data)) $template->setBody($data['body']);
if (array_key_exists('variables', $data)) $template->setVariables($data['variables']);