Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/29877/nossas lojas #9

Merged
merged 10 commits into from
Dec 13, 2024
Prev Previous commit
Next Next commit
ajuste no loader de nossas lojas
  • Loading branch information
Felipe-FCampos committed Nov 29, 2024
commit ff79a168dac3dfb4dff7796b741151ac4d278934
69 changes: 69 additions & 0 deletions loaders/searchDocuments.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { AppContext } from "site/apps/site.ts";
import { resourceRange } from "apps/vtex/utils/resourceRange.ts";
import type { Document } from "apps/vtex/utils/types.ts";
import { parseCookie } from "apps/vtex/utils/vtexId.ts";

interface Props {
/**
* @description Two-letter string that identifies the data entity.
*/
acronym: string;
/**
* @description Names of the fields that will be returned per document, separated by a comma ,. It is possible to fetch all fields using _all as the value of this query parameter. However, in order to avoid permission errors, we strongly recommend informing only the names of the exact fields that will be used.
*/
fields?: string;
/**
* @description Specification of filters.
*/
where?: string;
/**
* @description Inform a field name plus ASC to sort results by this field value in ascending order or DESC to sort by descending order.
*/
sort?: string;
/**
* @description Number of documents to be returned.
* @default 10
* @maxValue 100
* @minValue 1
*/
take?: number;
/**
* @description Skip how many documents
* @default 0
* @maxValue 100
* @minValue 0
*/
skip?: number;
}

/**
* @title Search documents - VTEX
* @docs https://developers.vtex.com/docs/api-reference/masterdata-api#get-/api/dataentities/-acronym-/search
*/
export default async function loader(
props: Props,
req: Request,
ctx: AppContext,
): Promise<Document[]> {
// @deno-ignore
const { vcs } = await ctx.invoke.vtex.loaders.config();
const { acronym, fields, where, sort, skip = 0, take = 10 } = props;
const { cookie } = parseCookie(req.headers, "alphabeto");
const limits = resourceRange(skip, take);

const documents = await vcs["GET /api/dataentities/:acronym/search"]({
acronym,
_fields: fields,
_where: where,
_sort: sort,
}, {
headers: {
accept: "application/vnd.vtex.ds.v10+json",
"content-type": "application/json",
//cookie,
"REST-Range": `resources=${limits.from}-${limits.to}`,
},
}).then((response) => response.json());

return documents;
}
10 changes: 6 additions & 4 deletions manifest.gen.ts
Original file line number Diff line number Diff line change
@@ -12,8 +12,9 @@ import * as $$$0 from "./loaders/availableIcons.ts";
import * as $$$1 from "./loaders/geolocation.ts";
import * as $$$2 from "./loaders/icons.ts";
import * as $$$3 from "./loaders/minicart.ts";
import * as $$$4 from "./loaders/user.ts";
import * as $$$5 from "./loaders/wishlist.ts";
import * as $$$4 from "./loaders/searchDocuments.ts";
import * as $$$5 from "./loaders/user.ts";
import * as $$$6 from "./loaders/wishlist.ts";
import * as $$$$$$0 from "./sections/Animation/Animation.tsx";
import * as $$$$$$1 from "./sections/BreadcrumbInstitucional/Breadcrumb.tsx";
import * as $$$$$$2 from "./sections/Category/CategoryBanner.tsx";
@@ -55,8 +56,9 @@ const manifest = {
"site/loaders/geolocation.ts": $$$1,
"site/loaders/icons.ts": $$$2,
"site/loaders/minicart.ts": $$$3,
"site/loaders/user.ts": $$$4,
"site/loaders/wishlist.ts": $$$5,
"site/loaders/searchDocuments.ts": $$$4,
"site/loaders/user.ts": $$$5,
"site/loaders/wishlist.ts": $$$6,
},
"sections": {
"site/sections/Animation/Animation.tsx": $$$$$$0,
17 changes: 7 additions & 10 deletions sections/NossasLojas/NossasLojas.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// deno-lint-ignore-file
import { Secret } from "apps/website/loaders/secret.ts";
import { type RichText } from "apps/admin/widgets.ts";

@@ -30,17 +31,13 @@ interface MasterDataResponse {

export async function loader({ items, apiKey }: ContentProps, _req: Request, ctx: AppContext){

try {
const masterdataStoreNumbers = await ctx.invoke.vtex.loaders.masterdata.searchDocuments({
acronym: "SM",
fields:"store_id,whatsapp",
where: "store_id is not null"
})
} catch(e){
console.log(e)
}
// @deno-ignore
const masterdataStoreNumbers = await ctx.invoke.site.loaders.searchDocuments({
acronym: "SM",
fields:"store_id,whatsapp",
where: "active=true"
}) as unknown as MasterDataResponse[]

const masterdataStoreNumbers = []
const { io } = await ctx.invoke.vtex.loaders.config()

const response = await io.query<Data,{}>({
1 change: 1 addition & 0 deletions sections/NossasLojas/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// deno-lint-ignore-file


export interface Data {