Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- type Order @model {
- id: ID!
- order_id: String!
- oloid: String!
- orderref: String!
- deliverymode: String!
- timeplaced: String!
- timemode: String
- status: String!
- kds_status: String!
- firstname: String!
- lastname: String!
- emailaddress: String!
- contactnumber:String!
- products: [Product] @connection(name: "OrderProducts")
- }
- type Product @model {
- name: String!
- quantity: String!
- totalcost: String!
- categoryName: String
- orders: Order @connection(name: "OrderProducts")
- }
- input CreateOrderInput {
- id: ID
- order_id: String!
- oloid: String!
- orderref: String!
- deliverymode: String!
- timeplaced: String!
- timemode: String
- status: String!
- kds_status: String!
- firstname: String!
- lastname: String!
- emailaddress: String!
- contactnumber: String!
- }
- input CreateProductInput {
- name: String!
- quantity: String!
- totalcost: String!
- categoryName: String
- productOrdersId: ID
- }
- export const createOrder = `mutation CreateOrder($input: CreateOrderInput!) {
- createOrder(input: $input) {
- id
- order_id
- oloid
- orderref
- deliverymode
- timeplaced
- timemode
- status
- kds_status
- firstname
- lastname
- emailaddress
- contactnumber
- products {
- items {
- name
- quantity
- totalcost
- categoryName
- }
- nextToken
- }
- }
- }
- `;
- AWS.config.update({
- region: 'us-east-2',
- credentials: new AWS.Credentials({
- accessKeyId: 'ACCESSKEY',
- secretAccessKey: 'SECRETACCESSKEY',
- }),
- });
- const url = awsconfig.aws_appsync_graphqlEndpoint;
- const region = awsconfig.aws_project_region;
- const client = new AWSAppSyncClient({
- url,
- region,
- auth: {
- type: AUTH_TYPE.API_KEY,
- apiKey: 'api-key-cadfadfasd',
- },
- disableOffline: true, // Uncomment for AWS Lambda
- });
- const products = [];
- for (let x = 0; x < data.products.length; x++) {
- let categoryName = '';
- if (data.products[x].custompassthroughdata) {
- const customData = JSON.parse(data.products[x].custompassthroughdata);
- if (customData && customData.productCategory) {
- categoryName = customData.productCategory;
- }
- }
- products.push(
- {
- name: data.products[x].name,
- quantity: data.products[x].quantity,
- totalcost: data.products[x].totalcost,
- categoryName,
- },
- );
- }
- (async () => {
- const result = await client.mutate({
- mutation: gql(createOrder),
- variables: {
- input: {
- order_id: data.id,
- oloid: data.oloid,
- orderref: data.orderref,
- deliverymode: data.deliverymode,
- timemode: data.timemode,
- timeplaced: data.timeplaced,
- status: data.status,
- firstname: userReq.body.firstname,
- lastname: userReq.body.lastname,
- emailaddress: userReq.body.emailaddress,
- contactnumber: userReq.body.contactnumber,
- products,
- },
- },
- });
- console.log(result.data.createOrder);
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement