won-games / api Goto Github PK
View Code? Open in Web Editor NEWStrapi API to our Ecommerce
Home Page: https://reactavancado.com.br/
Strapi API to our Ecommerce
Home Page: https://reactavancado.com.br/
Descrição do problema:
Ao usar o método service.create de Publisher, dentro do custom service Populate, recebo o seguinte erro no console:
{"data":null,"error":{"status":400,"name":"ValidationError","message":"Invalid payload submitted for the creation of an entity of type publisher. Expected an object, but got undefined","details":{}}}
Gostaria de ajuda para entender e resolver este problema.
Abaixo segue o código do custom service Populate:
"use strict";
/**
* populate service.
*/
const axios = require("axios");
const slugify = require("slugify");
async function getGameInfo(slug) {
const jsdom = require("jsdom");
const { JSDOM } = jsdom;
const body = await axios.get(`https://www.gog.com/game/${slug}`);
const dom = new JSDOM(body.data);
const description = dom.window.document.querySelector(".description");
return {
rating: "BR0",
short_description: description.textContent.slice(0, 160),
description: description.innerHTML,
};
}
module.exports = ({ strapi }) => ({
async populate(params) {
const gogApiUrl = `https://www.gog.com/games/ajax/filtered?mediaType=game&page=1&sort=popularity`;
const {
data: { products },
} = await axios.get(gogApiUrl);
const publisher = {
name: products[0].publisher,
slug: slugify(products[0].publisher).toLowerCase(),
};
console.log(strapi);
await strapi.service("api::publisher.publisher").create(publisher);
return publisher;
// console.log(await getGameInfo(products[0].slug));
},
});
No console os objetos products e publisher estão no formado e com os dados correspondentes ao esperado, o erro ocorre ao rodar o curl -X POST http://localhost:1337/api/games/populate
.
Antes de desabilitar a opção Draft/Publish dentro de Advanced Settings da tabela Publisher, o erro era:
[2022-01-12 11:03:39.380] error: Cannot set property 'publishedAt' of undefined
TypeError: Cannot set property 'publishedAt' of undefined
Após desabilitar essa opção dentro da tabela, o erro passa a ser:
{"data":null,"error":{"status":400,"name":"ValidationError","message":"Invalid payload submitted for the creation of an entity of type publisher. Expected an object, but got undefined","details":{}}}
Gostaria de ajuda para avançar este estágio.
Desde já, obrigado a todos.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.