Files
libredesk/internal/template/queries.sql
T
Abhinav Raut 50188352a5 fix: Use SyncedEnforcer in casbin, fixes panics.
feat: store user roles in user roles table, drops the roles table on users table.
feat: standardize column names in schema, renames disabled bool to enables.
- vue router fixes to allow components / pages to rerender after creating an object in db.
- minor fixes and refactors.
2025-01-22 03:40:32 +05:30

38 lines
1.1 KiB
SQL

-- name: insert
INSERT INTO templates ("name", body, is_default, subject, type)
VALUES ($1, $2, $3, $4, $5);
-- name: update
WITH u AS (
UPDATE templates
SET
name = CASE WHEN $6::template_type = 'email_outgoing' THEN $2 ELSE name END,
body = $3,
is_default = $4,
subject = $5,
type = $6::template_type,
updated_at = NOW()
WHERE id = $1
RETURNING id
)
UPDATE templates
SET is_default = FALSE
WHERE id != $1 AND $4 = TRUE;
-- name: get-default
SELECT id, type, name, body, subject FROM templates WHERE is_default is TRUE;
-- name: get-all
SELECT id, type, name, is_default, updated_at FROM templates WHERE type = $1 ORDER BY updated_at DESC;
-- name: get-template
SELECT id, type, name, body, subject, is_default, type FROM templates WHERE id = $1;
-- name: delete
DELETE FROM templates WHERE id = $1;
-- name: get-by-name
SELECT id, type, name, body, subject, is_default, type FROM templates WHERE name = $1;
-- name: is-builtin
SELECT EXISTS(SELECT 1 FROM templates WHERE id = $1 AND is_builtin is TRUE);