mirror of
https://github.com/Dvorinka/Bookra.git
synced 2026-10-28 07:41:16 +00:00
- Finish Paddle-to-Stripe billing migration; drop paddle/stripe libs - Renumber migrations; add 00012 memberships+manage_token, 00013 location_type_capacity - Add tests: admin, auth, bookings customer service - Remove graphify-out artifacts and stale env files Authored By: TDvorak <[email protected]> Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
56 lines
2.0 KiB
Go
56 lines
2.0 KiB
Go
package db
|
|
|
|
import (
|
|
"context"
|
|
)
|
|
|
|
func (r *PGRepository) ListEmailTemplates(ctx context.Context, tenantID string) ([]EmailTemplateRecord, error) {
|
|
rows, err := r.pool.Query(ctx, `
|
|
SELECT id, tenant_id, type, subject, body_html, body_text, is_enabled, updated_at
|
|
FROM email_templates
|
|
WHERE tenant_id = $1
|
|
ORDER BY type
|
|
`, tenantID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
|
|
var records []EmailTemplateRecord
|
|
for rows.Next() {
|
|
var rec EmailTemplateRecord
|
|
if err := rows.Scan(&rec.ID, &rec.TenantID, &rec.Type, &rec.Subject, &rec.BodyHTML, &rec.BodyText, &rec.IsEnabled, &rec.UpdatedAt); err != nil {
|
|
return nil, err
|
|
}
|
|
records = append(records, rec)
|
|
}
|
|
return records, rows.Err()
|
|
}
|
|
|
|
func (r *PGRepository) GetEmailTemplate(ctx context.Context, tenantID string, templateType string) (EmailTemplateRecord, error) {
|
|
var rec EmailTemplateRecord
|
|
err := r.pool.QueryRow(ctx, `
|
|
SELECT id, tenant_id, type, subject, body_html, body_text, is_enabled, updated_at
|
|
FROM email_templates
|
|
WHERE tenant_id = $1 AND type = $2
|
|
`, tenantID, templateType).Scan(&rec.ID, &rec.TenantID, &rec.Type, &rec.Subject, &rec.BodyHTML, &rec.BodyText, &rec.IsEnabled, &rec.UpdatedAt)
|
|
return rec, err
|
|
}
|
|
|
|
func (r *PGRepository) UpsertEmailTemplate(ctx context.Context, params EmailTemplateRecord) (EmailTemplateRecord, error) {
|
|
var rec EmailTemplateRecord
|
|
err := r.pool.QueryRow(ctx, `
|
|
INSERT INTO email_templates (tenant_id, type, subject, body_html, body_text, is_enabled)
|
|
VALUES ($1, $2, $3, $4, $5, $6)
|
|
ON CONFLICT (tenant_id, type) DO UPDATE SET
|
|
subject = EXCLUDED.subject,
|
|
body_html = EXCLUDED.body_html,
|
|
body_text = EXCLUDED.body_text,
|
|
is_enabled = EXCLUDED.is_enabled,
|
|
updated_at = now()
|
|
RETURNING id, tenant_id, type, subject, body_html, body_text, is_enabled, updated_at
|
|
`, params.TenantID, params.Type, params.Subject, params.BodyHTML, params.BodyText, params.IsEnabled).Scan(
|
|
&rec.ID, &rec.TenantID, &rec.Type, &rec.Subject, &rec.BodyHTML, &rec.BodyText, &rec.IsEnabled, &rec.UpdatedAt)
|
|
return rec, err
|
|
}
|