Skip to content

Commit

Permalink
feat: submit review (#973)
Browse files Browse the repository at this point in the history
* feat: submit review

* fix: remove comment

* fix: recommended settings
  • Loading branch information
ApMatheus authored Dec 18, 2024
1 parent 3ca9fe8 commit e79fd4b
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 1 deletion.
35 changes: 35 additions & 0 deletions konfidency/actions/submitReviews.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { AppContext } from "../mod.ts";
import { ResponseWriteReview, WriteReview } from "../utils/types.ts";
import { logger } from "@deco/deco/o11y";

export interface Props {
/**
* @title Product SKU
*/
sku: string;
review: WriteReview;
}

export default async function action(props: Props, _req: Request, ctx: AppContext): Promise<ResponseWriteReview | null> {

const { customer, api } = ctx
const { review, sku } = props

try {
const response = await api[`POST /:customer/:sku/review`]({
sku: sku,
customer,
}, {
body: {
...review,
},
}).then((r) => r.json())
return await response
} catch (error) {
const errorObj = error as { name: string; message: string };
logger.error(`{ errorName: ${errorObj.name},
errorMessage: ${errorObj.message} }`);
return null
}

}
4 changes: 4 additions & 0 deletions konfidency/manifest.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
// This file is automatically updated during development when running `dev.ts`.

import * as $$$0 from "./loaders/productDetailsPage.ts";
import * as $$$$$$$$$0 from "./actions/submitReviews.ts";

const manifest = {
"loaders": {
"konfidency/loaders/productDetailsPage.ts": $$$0,
},
"actions": {
"konfidency/actions/submitReviews.ts": $$$$$$$$$0,
},
"name": "konfidency",
"baseUrl": import.meta.url,
};
Expand Down
7 changes: 6 additions & 1 deletion konfidency/utils/client.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { PDPReview } from "./types.ts";
import type { PDPReview, WriteReview, ResponseWriteReview } from "./types.ts";

export interface API {
"GET /:customer/:sku/summary": {
Expand All @@ -8,4 +8,9 @@ export interface API {
pageSize: number;
};
};

"POST /:customer/:sku/review": {
response: ResponseWriteReview
body: WriteReview;
}
}
24 changes: 24 additions & 0 deletions konfidency/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,27 @@ export interface Composition {
export interface CustomerSettings {
minStarsHighlightPDP: number;
}

export interface WriteReview {
userId: string;
email: string;
rating: number;
text: string;
recommended?: boolean;
}

export interface ResponseWriteReview {
helpful: number;
unhelpful: number;
verified: boolean;
status: string;
_id: string;
created: string;
customer: string;
userId: string;
name: string;
sku: string;
text: string;
recommended: boolean;
rating: number;
}

0 comments on commit e79fd4b

Please sign in to comment.