Skip to content

Commit

Permalink
feat: partial update cookie
Browse files Browse the repository at this point in the history
  • Loading branch information
moeakwak committed Jun 9, 2024
1 parent 7842898 commit 66051ca
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ export const extendRouter = (router: Router) => {
200: {
content: {
"application/json": {
schema: responseDataSchema(z.null()),
schema: responseDataSchema(PoeAccountCookiesModel),
},
},
description: "success",
Expand All @@ -371,21 +371,29 @@ export const extendRouter = (router: Router) => {
const data = c.req.valid("json");

const instanceData = c.var.instanceData;
const poe_cookies = instanceData.poe_cookies.filter(
(cookie) => !data.some((newCookie) => newCookie.name === cookie.name),
);
poe_cookies.push(...data);

const instance = await db
.update(serviceInstances)
.set({
data: {
...instanceData,
poe_cookies: data,
poe_cookies,
} as PoekmonSharedInstanceData,
})
.where(eq(serviceInstances.id, c.var.instanceId))
.returning();

if (instance.length !== 1) {
return c.json(err(`Error Update: ${instance.length} instance returned`), 400);
}
c.set("instanceData", instance[0]!.data as PoekmonSharedInstanceData);
return c.json(ok(null));
const newInstanceData = instance[0]!.data as PoekmonSharedInstanceData;
c.set("instanceData", newInstanceData);

return c.json(ok(newInstanceData.poe_cookies));
});

const createLogRoute = createRoute({
Expand Down
2 changes: 1 addition & 1 deletion src/schema/service/poekmon-shared.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const PoeAccountCookieSchema = z
.object({
name: z.string(),
value: z.string(),
expired_at: z.number(),
expired_at: z.number().nullable(),
});

export const PoekmonSharedAccountDataSchema = z.object({
Expand Down

0 comments on commit 66051ca

Please sign in to comment.