xbenjii / Prestan

PrestaShop Node.js API Library [UNMAINTAINED]
MIT License
20 stars 7 forks source link

I gonna try you lib with GraphQL/Apollo (tips?) #13

Closed MichelDiz closed 7 years ago

MichelDiz commented 7 years ago

I just met your library. I was looking for a solution to add clients via Json blank Schema (seems impossible). Then I met this repo. I was previously configuring my GraphQL with a simple Fetch straight into the API path. Your code would make my application cleaner.

I will see some of the other issues, but if you can advance me:

How do I add a customer? Or a product?

best regards

MichelDiz commented 7 years ago

I got it! This is the best library related to Prestashop with Javascript. Thank you very much!

It would be great if they could periodically review the code and improve the documentation.

To work I have created this code in my Resolvers and it works wonderfully well.

CreateCustomers(input) { 
      prestan.get('customers', {schema: 'blank'})
      .then(function(response) {
        console.log(input, "passando input");
          response.prestashop.customer.id = null;
          response.prestashop.customer.id_default_group = input.idDefaultGroup ,
          response.prestashop.customer.id_lang = input.idLang ,
          response.prestashop.customer.newsletter_date_add = null,
          response.prestashop.customer.ip_registration_newsletter = null,
          response.prestashop.customer.last_passwd_gen = null,
          response.prestashop.customer.secure_key = null,
          response.prestashop.customer.deleted = null,
          response.prestashop.customer.passwd = input.passwd,
          response.prestashop.customer.lastname = input.lastname,
          response.prestashop.customer.firstname = input.firstname,
          response.prestashop.customer.email = input.email,
          response.prestashop.customer.id_gender = input.idGender,
          response.prestashop.customer.birthday = input.birthday,
          response.prestashop.customer.newsletter = input.newsletter,
          response.prestashop.customer.optin = input.optin,
          response.prestashop.customer.website = input.website,
          response.prestashop.customer.company = input.company,
          response.prestashop.customer.siret = null,
          response.prestashop.customer.ape = null,
          response.prestashop.customer.outstanding_allow_amount = null,
          response.prestashop.customer.show_public_prices = null,
          response.prestashop.customer.id_risk = null,
          response.prestashop.customer.max_payment_days = null,
          response.prestashop.customer.active = 1,
          response.prestashop.customer.note = null,
          response.prestashop.customer.is_guest = null,
          response.prestashop.customer.id_shop = input.idShop,
          response.prestashop.customer.id_shop_group = input.idShopGroup,
          response.prestashop.customer.date_add = null,
          response.prestashop.customer.date_upd = null,
          response.prestashop.customer.reset_password_token = null,
          response.prestashop.customer.reset_password_validity = null,
          prestan.add('customers', response).then(function(resp){
              console.log("resp", resp);
              return resp;
          });  
      }).catch(function(errors) {
          console.log("ne",errors);
          return errors;
      });
    }

I intended to create a customer by following the prestashop standards. Through this code creating a customer through the API I was able to do exactly what I wanted and now I can create a user through that Mutation on GraphiQL.

mutation
{
  createUser (input: {
    idShopGroup: 1,
    idShop: 1,
    idGender: 1,
    idDefaultGroup: 1,
    idLang: 1,
    company: "Great Company of all times",
    firstname: "Michel Conrado",
    lastname: "A. Diz",
    email: "michelconrado@greatcompany.com",
    passwd: "DumbyPass1234",
    birthday: "1989-02-25",
    newsletter: 1,
    optin: 1,
    website: "www.greatcompany.com.br"
  }) {
 firstname
  } 

}