오류 수정
This commit is contained in:
+2
-1
@@ -53,6 +53,7 @@ export async function resolveLinkTemplateId(
|
|||||||
const createLinkSchema = z.object({
|
const createLinkSchema = z.object({
|
||||||
userId: z.string().uuid().optional(),
|
userId: z.string().uuid().optional(),
|
||||||
templateId: z.string().uuid().optional(),
|
templateId: z.string().uuid().optional(),
|
||||||
|
templateSlug: z.string().optional(),
|
||||||
originalUrl: z.string().url().optional(),
|
originalUrl: z.string().url().optional(),
|
||||||
title: z.string().optional(),
|
title: z.string().optional(),
|
||||||
description: z.string().optional(),
|
description: z.string().optional(),
|
||||||
@@ -219,7 +220,7 @@ export async function linkRoutes(fastify: FastifyInstance) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const originalUrl = data.originalUrl || 'https://angkorlifes.com';
|
const originalUrl = data.originalUrl || 'https://angkorlifes.com';
|
||||||
const resolvedTemplateId = await resolveLinkTemplateId(data.templateId, null);
|
const resolvedTemplateId = await resolveLinkTemplateId(data.templateId, data.templateSlug);
|
||||||
|
|
||||||
const result = await db.query(
|
const result = await db.query(
|
||||||
`INSERT INTO links (
|
`INSERT INTO links (
|
||||||
|
|||||||
@@ -46,6 +46,9 @@ describe('POST /api/sdk/v1/links', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('accepts payloads without originalUrl and derives a fallback destination', async () => {
|
it('accepts payloads without originalUrl and derives a fallback destination', async () => {
|
||||||
|
mockQuery.mockResolvedValueOnce({
|
||||||
|
rows: [{ id: 'default-template-id' }],
|
||||||
|
});
|
||||||
mockQuery.mockResolvedValueOnce({
|
mockQuery.mockResolvedValueOnce({
|
||||||
rows: [{
|
rows: [{
|
||||||
id: LINK_ID,
|
id: LINK_ID,
|
||||||
@@ -70,7 +73,7 @@ describe('POST /api/sdk/v1/links', () => {
|
|||||||
originalUrl: 'https://example.com/emoji/detail',
|
originalUrl: 'https://example.com/emoji/detail',
|
||||||
});
|
});
|
||||||
|
|
||||||
const insertCall = mockQuery.mock.calls[0];
|
const insertCall = mockQuery.mock.calls[1];
|
||||||
expect(insertCall[0]).toMatch(/INSERT INTO links/);
|
expect(insertCall[0]).toMatch(/INSERT INTO links/);
|
||||||
expect(insertCall[1][3]).toBe('https://example.com/emoji/detail');
|
expect(insertCall[1][3]).toBe('https://example.com/emoji/detail');
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -60,6 +60,7 @@ export async function sdkRoutes(fastify: FastifyInstance) {
|
|||||||
attributionWindowHours: z.number().int().min(1).max(2160).optional(),
|
attributionWindowHours: z.number().int().min(1).max(2160).optional(),
|
||||||
expiresAt: z.string().datetime().optional(),
|
expiresAt: z.string().datetime().optional(),
|
||||||
templateId: z.string().uuid().optional(),
|
templateId: z.string().uuid().optional(),
|
||||||
|
templateSlug: z.string().optional(),
|
||||||
userId: z.string().uuid().optional(),
|
userId: z.string().uuid().optional(),
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -67,7 +68,7 @@ export async function sdkRoutes(fastify: FastifyInstance) {
|
|||||||
const originalUrl = body.originalUrl || 'https://angkorlifes.com';
|
const originalUrl = body.originalUrl || 'https://angkorlifes.com';
|
||||||
|
|
||||||
const shortCode = body.customCode || 'sdk-link';
|
const shortCode = body.customCode || 'sdk-link';
|
||||||
const resolvedTemplateId = await resolveLinkTemplateId(body.templateId, null);
|
const resolvedTemplateId = await resolveLinkTemplateId(body.templateId, body.templateSlug);
|
||||||
|
|
||||||
const result = await db.query(
|
const result = await db.query(
|
||||||
`INSERT INTO links (
|
`INSERT INTO links (
|
||||||
|
|||||||
Reference in New Issue
Block a user