Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #33 from Mika24boss/Khoi
Browse files Browse the repository at this point in the history
FINALALALADLASKDASLDKLASDJ
  • Loading branch information
HoangMinhKhoiPham authored Dec 1, 2023
2 parents dd09bfa + 1d3745c commit 5bb109d
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 19 deletions.
20 changes: 14 additions & 6 deletions frontend/src/routes/orders/[orderID]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
UPDATE_ORDER_STATUS
} from "../../../mutations/ordersMutation.js";
const client = new ApolloClient({
let client = new ApolloClient({
uri: 'https://bwm.happyfir.com/graphql/orders',
cache: new InMemoryCache()
});
Expand Down Expand Up @@ -78,7 +78,7 @@
function UpdateStatusOrder(status) {
statusOrder = document.getElementById(status).innerText;
//UpdateStatus(convertStatusReverse(status));
UpdateStatus(convertStatusReverse(status));
}
function convertStatus(backendStatus) {
Expand Down Expand Up @@ -111,10 +111,18 @@
}
}
/*async function UpdateStatus(newStatus) {
console.log({ orderID: parseInt(orderID), status: newStatus })
async function UpdateStatus(newStatus) {
console.log({orderID: parseInt(orderID), status: newStatus})
try {
const { data } = await updateStatusMutation({ variables: { orderID: parseInt(orderID), status: newStatus } });
const {data} = await updateStatusMutation(
{
variables: {
orderID: parseInt(orderID), status: newStatus
}
}
)
;
// Handle the response data as needed
console.log('Order status updated successfully:', data.updateOrderStatus);
Expand All @@ -123,7 +131,7 @@
console.error('Error updating order status:', err);
}
}*/
}
</script>

Expand Down
12 changes: 6 additions & 6 deletions frontend/src/routes/quotations/[quotationID]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
import {GET_ITEM} from "../../../mutations/itemsMutation.js";
const client = new ApolloClient({
// uri: 'https://bwm.happyfir.com/graphql/create_request',
uri: "http://localhost:8000/graphql/create_request",
uri: 'https://bwm.happyfir.com/graphql/create_request',
// uri: "http://localhost:8000/graphql/create_request",
cache: new InMemoryCache()
});
Expand All @@ -44,7 +44,7 @@
id: quotationID,
}
});
console.log(response)
let pickUpAddressResponse = await getAddress({
variables: {
id: response.data.quotation.pickUpAddress
Expand Down Expand Up @@ -93,9 +93,9 @@
//quotation = (await jobService.getJobByID(jobID, user.token))[0];
/* orderItems = [{itemName: 'Mango', quantity: '10'},
{itemName: 'Couch', quantity: '500'},
{itemName: 'Number 10 machine screw (0.190 inch major diameter)', quantity: '51700'}];*/
/* orderItems = [{itemName: 'Mango', quantity: '10'},
{itemName: 'Couch', quantity: '500'},
{itemName: 'Number 10 machine screw (0.190 inch major diameter)', quantity: '51700'}];*/
if (quotation == null) {
alert('No quotation has an ID #' + quotationID + '.');
Expand Down
15 changes: 13 additions & 2 deletions frontend/src/routes/quotations/payment/[quotationID]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import {browser} from "$app/environment";
import {ApolloClient, InMemoryCache} from "@apollo/client/core";
import {mutation, setClient} from "svelte-apollo";
import {GET_QUOTATION} from "../../../../mutations/quotationMutation.js";
import {DELETE_QUOTATION, GET_QUOTATION} from "../../../../mutations/quotationMutation.js";
import {ADD_PAYMENT} from "../../../../mutations/paymentMutatiion.js";
import {ADD_ORDER} from "../../../../mutations/ordersMutation.js";
import {goto} from "$app/navigation";
Expand All @@ -21,7 +21,7 @@
let pageTitle = "Payment | Quotation #" + quotationID;
let user;
var isWaiting = true;
let orderMutation, quotationInfo, paymentMutation, paymentInfo
let orderMutation, quotationInfo, paymentMutation, paymentInfo, deleteQuotation
loadPage()
async function loadPage() {
Expand All @@ -38,6 +38,7 @@
const quotationMutation = mutation(GET_QUOTATION)
paymentMutation = mutation(ADD_PAYMENT)
orderMutation = mutation(ADD_ORDER)
deleteQuotation = mutation(DELETE_QUOTATION)
if (user == null || (user.role !== 'GOLD-CLIENT' && user.role !== 'REGULAR-CLIENT')) {
await goto('/');
Expand Down Expand Up @@ -111,6 +112,16 @@
} catch (e) {
throw Error("Order failed")
}
try {
const response = await deleteQuotation({
variables: {
quotationID: quotationID,
}
})
console.log(response)
} catch (e) {
throw Error("Delete Quotation failed")
}
alert("Order created!");
await goto('/quotations');
Expand Down
6 changes: 1 addition & 5 deletions server/schema/orderSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,11 +309,7 @@ const mutation = new GraphQLObjectType({
orderID: {type: GraphQLInt},
status: {type: GraphQLString},
},
async resolve(args, context) {
const deliveryMan = await DeliveryMan.findById(protect(context.headers['authorization']).id).select('-password');
if (!deliveryMan) {
throw new Error('User not authorized')
}
async resolve(parents, args, context) {
const order = await Order.findOne({orderID: {$eq: args.orderID}});
if (!order) {
throw new Error('Order not found')
Expand Down

0 comments on commit 5bb109d

Please sign in to comment.