Advertisement
Guest User

Untitled

a guest
Jul 19th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.25 KB | None | 0 0
  1. type Order @model {
  2. id: ID!
  3. order_id: String!
  4. oloid: String!
  5. orderref: String!
  6. deliverymode: String!
  7. timeplaced: String!
  8. timemode: String
  9. status: String!
  10. kds_status: String!
  11. firstname: String!
  12. lastname: String!
  13. emailaddress: String!
  14. contactnumber:String!
  15. products: [Product] @connection(name: "OrderProducts")
  16. }
  17.  
  18. type Product @model {
  19. name: String!
  20. quantity: String!
  21. totalcost: String!
  22. categoryName: String
  23. orders: Order @connection(name: "OrderProducts")
  24. }
  25.  
  26. input CreateOrderInput {
  27. id: ID
  28. order_id: String!
  29. oloid: String!
  30. orderref: String!
  31. deliverymode: String!
  32. timeplaced: String!
  33. timemode: String
  34. status: String!
  35. kds_status: String!
  36. firstname: String!
  37. lastname: String!
  38. emailaddress: String!
  39. contactnumber: String!
  40. }
  41.  
  42. input CreateProductInput {
  43. name: String!
  44. quantity: String!
  45. totalcost: String!
  46. categoryName: String
  47. productOrdersId: ID
  48. }
  49.  
  50. export const createOrder = `mutation CreateOrder($input: CreateOrderInput!) {
  51. createOrder(input: $input) {
  52. id
  53. order_id
  54. oloid
  55. orderref
  56. deliverymode
  57. timeplaced
  58. timemode
  59. status
  60. kds_status
  61. firstname
  62. lastname
  63. emailaddress
  64. contactnumber
  65. products {
  66. items {
  67. name
  68. quantity
  69. totalcost
  70. categoryName
  71. }
  72. nextToken
  73. }
  74. }
  75. }
  76. `;
  77.  
  78. AWS.config.update({
  79. region: 'us-east-2',
  80. credentials: new AWS.Credentials({
  81. accessKeyId: 'ACCESSKEY',
  82. secretAccessKey: 'SECRETACCESSKEY',
  83. }),
  84. });
  85. const url = awsconfig.aws_appsync_graphqlEndpoint;
  86. const region = awsconfig.aws_project_region;
  87. const client = new AWSAppSyncClient({
  88. url,
  89. region,
  90. auth: {
  91. type: AUTH_TYPE.API_KEY,
  92. apiKey: 'api-key-cadfadfasd',
  93. },
  94. disableOffline: true, // Uncomment for AWS Lambda
  95. });
  96. const products = [];
  97. for (let x = 0; x < data.products.length; x++) {
  98. let categoryName = '';
  99. if (data.products[x].custompassthroughdata) {
  100. const customData = JSON.parse(data.products[x].custompassthroughdata);
  101. if (customData && customData.productCategory) {
  102. categoryName = customData.productCategory;
  103. }
  104. }
  105. products.push(
  106. {
  107. name: data.products[x].name,
  108. quantity: data.products[x].quantity,
  109. totalcost: data.products[x].totalcost,
  110. categoryName,
  111. },
  112. );
  113. }
  114. (async () => {
  115. const result = await client.mutate({
  116. mutation: gql(createOrder),
  117. variables: {
  118. input: {
  119. order_id: data.id,
  120. oloid: data.oloid,
  121. orderref: data.orderref,
  122. deliverymode: data.deliverymode,
  123. timemode: data.timemode,
  124. timeplaced: data.timeplaced,
  125. status: data.status,
  126. firstname: userReq.body.firstname,
  127. lastname: userReq.body.lastname,
  128. emailaddress: userReq.body.emailaddress,
  129. contactnumber: userReq.body.contactnumber,
  130. products,
  131. },
  132. },
  133. });
  134. console.log(result.data.createOrder);
  135. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement