-
Notifications
You must be signed in to change notification settings - Fork 0
/
mod.ts
56 lines (45 loc) · 1.6 KB
/
mod.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { Hono } from "hono";
import { logger } from 'hono/logger'
import { configureAppServer } from "@shopware-ag/app-server-sdk/integration/hono";
import { DenoKVRepository } from "@shopware-ag/app-server-sdk/integration/deno-kv";
import {
AppServer,
ShopInterface,
Context,
SimpleShop,
} from "@shopware-ag/app-server-sdk";
import {
ActionButtonRequest
} from "@shopware-ag/app-server-sdk/types";
import { createNotificationResponse } from "@shopware-ag/app-server-sdk/helper/app-actions";
import { EntityRepository } from "@shopware-ag/app-server-sdk/helper/admin-api";
import { Criteria } from "@shopware-ag/app-server-sdk/helper/criteria";
const app = new Hono();
app.use(logger());
declare module "hono" {
interface ContextVariableMap {
app: AppServer;
shop: ShopInterface;
context: Context;
}
}
configureAppServer(app, {
appName: "Test",
appSecret: "Test",
shopRepository: new DenoKVRepository()
});
type Product = {
id: string;
name: string;
};
app.post("/app/action-button", async (c) => {
const ctx = c.get("context") as Context<SimpleShop, ActionButtonRequest>;
const repository = new EntityRepository<Product>(ctx.httpClient, "product");
// get the products clicked by action button
const entitySearchResult = await repository.search(new Criteria(ctx.payload.data.ids));
console.log(entitySearchResult.total);
console.log(entitySearchResult.first()?.name)
await repository.upsert(entitySearchResult.data.map(product => ({ id: product.id, name: 'yippiee' })));
return createNotificationResponse("success", "Product name updated yeaaa");
});
export default app;