feat(saves): Обновление существующих публикаций
This commit is contained in:
@ -175,6 +175,63 @@ export const savesController = new Elysia({ prefix: '/saves' })
|
||||
}
|
||||
)
|
||||
|
||||
.patch(
|
||||
'/:id',
|
||||
async ({ params: { id }, body, user, set }) => {
|
||||
if (!user) {
|
||||
set.status = 401;
|
||||
return { error: 'Unauthorized' };
|
||||
}
|
||||
|
||||
const saveId = Number(id);
|
||||
if (isNaN(saveId)) {
|
||||
set.status = 400;
|
||||
return { error: 'Invalid save ID' };
|
||||
}
|
||||
|
||||
try {
|
||||
const updated = await savesService.update(saveId, user.id, body);
|
||||
|
||||
return {
|
||||
id: updated.id,
|
||||
name: updated.name,
|
||||
type: updated.type,
|
||||
description: updated.description,
|
||||
tags: updated.tags,
|
||||
visibility: updated.visibility,
|
||||
shareUrl: updated.visibility === 'link' ? updated.shareUrl : undefined,
|
||||
updatedAt: updated.updatedAt.toISOString(),
|
||||
};
|
||||
} catch (error) {
|
||||
if (error instanceof Error && error.message.includes('not found')) {
|
||||
set.status = 404;
|
||||
return { error: 'Save not found or access denied' };
|
||||
}
|
||||
set.status = 500;
|
||||
return {
|
||||
error: error instanceof Error ? error.message : 'Failed to update save'
|
||||
};
|
||||
}
|
||||
},
|
||||
{
|
||||
params: t.Object({
|
||||
id: t.String(),
|
||||
}),
|
||||
body: t.Object({
|
||||
name: t.Optional(t.String()),
|
||||
description: t.Optional(t.String()),
|
||||
tags: t.Optional(t.Array(t.String())),
|
||||
visibility: t.Optional(t.Union([t.Literal('public'), t.Literal('link')])),
|
||||
}),
|
||||
detail: {
|
||||
tags: ['Saves'],
|
||||
summary: 'Update save',
|
||||
description: 'Updates save metadata (owner only)',
|
||||
},
|
||||
auth: true
|
||||
}
|
||||
)
|
||||
|
||||
.post(
|
||||
'/external',
|
||||
async ({ body, user, set }) => {
|
||||
|
||||
Reference in New Issue
Block a user