|
@@ -3,6 +3,7 @@
|
|
|
const getGQL = (url) => async (query, variables) => {
|
|
|
try {
|
|
|
const token = localStorage.token;
|
|
|
+ console.log(token);
|
|
|
const res = await fetch(url, {
|
|
|
method: 'POST',
|
|
|
headers: {
|
|
@@ -127,9 +128,59 @@ const goodById = async (_id) => {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
+const getOrders = async () => {
|
|
|
+ try {
|
|
|
+ const { data } = await gql(
|
|
|
+ `query orders {
|
|
|
+ OrderFind(query:"[{}]")
|
|
|
+ {
|
|
|
+ _id
|
|
|
+ total
|
|
|
+ orderGoods {
|
|
|
+ price
|
|
|
+ count
|
|
|
+ total
|
|
|
+ good {
|
|
|
+ name
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}`,
|
|
|
+ {}
|
|
|
+ );
|
|
|
+
|
|
|
+ return data.OrderFind;
|
|
|
+ } catch (e) {
|
|
|
+ console.error(e);
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
+const makeOrder = async (id) => {
|
|
|
+ try {
|
|
|
+ const { data } = await gql(
|
|
|
+ ` mutation makeOrder($id:ID){
|
|
|
+ OrderUpsert(order:{
|
|
|
+ orderGoods:[
|
|
|
+ {count:1,good:{_id:$id}}
|
|
|
+ ]
|
|
|
+ }){
|
|
|
+ _id,total
|
|
|
+ }
|
|
|
+ }`,
|
|
|
+ { id }
|
|
|
+ );
|
|
|
+
|
|
|
+ return data.OrderUpsert;
|
|
|
+ } catch (e) {
|
|
|
+ console.error(e);
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
console.log(await loginGQL('test2021121', 'test2021121'), 'loginGQL');
|
|
|
console.log(await registerGQL('1234332121', '123'), 'registerGQL');
|
|
|
console.log(await categoriesGQL(), 'categoriesGQL');
|
|
|
console.log(await goodsGQL(), 'goodsGQL');
|
|
|
console.log(await categoryById('5dc4b2553f23b553bf354100'), 'categoryById');
|
|
|
console.log(await goodById('61afa803c750c12ba6ba444a'), 'goodById');
|
|
|
+console.log(await makeOrder('5dc886550e36db246e3049c0', 2), 'makeOrder');
|
|
|
+console.log(await getOrders(), 'getOrders');
|