mirror of
https://github.com/freedbygrace/DynamoDNS.git
synced 2026-07-28 20:38:56 +00:00
Improve domain creation and update flexibility by allowing optional provider ID.
Replit-Commit-Author: Agent Replit-Commit-Session-Id: 9111ef36-26c8-4085-84ca-a35dc1fec1b5 Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/7083d608-d6d3-4a6a-9a27-6286c5109627/b8028253-9393-4805-8293-3b06d95ed5e3.jpg
This commit is contained in:
+15
-12
@@ -203,21 +203,24 @@ export class DatabaseStorage implements IStorage {
|
||||
try {
|
||||
// Use raw SQL to avoid schema issues
|
||||
const now = new Date().toISOString();
|
||||
|
||||
// Build SQL dynamically based on whether providerId is provided
|
||||
let columnsSQL;
|
||||
let valuesSQL;
|
||||
|
||||
if (domain.providerId) {
|
||||
columnsSQL = sql`id, name, organization_id, is_active, provider_id, created_at`;
|
||||
valuesSQL = sql`gen_random_uuid(), ${domain.name}, ${domain.organizationId}, ${domain.isActive}, ${domain.providerId}, ${now}`;
|
||||
} else {
|
||||
columnsSQL = sql`id, name, organization_id, is_active, created_at`;
|
||||
valuesSQL = sql`gen_random_uuid(), ${domain.name}, ${domain.organizationId}, ${domain.isActive}, ${now}`;
|
||||
}
|
||||
|
||||
const query = sql`
|
||||
INSERT INTO domains (
|
||||
id,
|
||||
name,
|
||||
organization_id,
|
||||
is_active,
|
||||
provider_id,
|
||||
created_at
|
||||
${columnsSQL}
|
||||
) VALUES (
|
||||
gen_random_uuid(),
|
||||
${domain.name},
|
||||
${domain.organizationId},
|
||||
${domain.isActive},
|
||||
${domain.providerId || null},
|
||||
${now}
|
||||
${valuesSQL}
|
||||
)
|
||||
RETURNING
|
||||
id,
|
||||
|
||||
+10
-1
@@ -215,7 +215,16 @@ export async function registerRoutes(app: Express): Promise<Server> {
|
||||
try {
|
||||
// Use id as string without parsing to int
|
||||
const id = req.params.id;
|
||||
const validatedData = insertDomainSchema.partial().parse(req.body);
|
||||
|
||||
// Create custom validation schema with optional providerId
|
||||
const domainUpdateSchema = z.object({
|
||||
name: z.string().optional(),
|
||||
organizationId: z.string().uuid().optional(),
|
||||
providerId: z.string().uuid().optional().nullable(),
|
||||
isActive: z.boolean().optional()
|
||||
});
|
||||
|
||||
const validatedData = domainUpdateSchema.parse(req.body);
|
||||
|
||||
const updatedDomain = await storage.updateDomain(id, validatedData);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user