Skip to content

Commit 5447e44

Browse files
*
1 parent be28a20 commit 5447e44

File tree

6 files changed

+48
-130
lines changed

6 files changed

+48
-130
lines changed

graphql/resolvers/Company/index.js

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -65,26 +65,24 @@ export default {
6565
});
6666
},
6767
updateCompany: async (parent, { _id, company }, context, info) => {
68-
return new Promise((resolve, reject) => {
69-
Company.findByIdAndUpdate(
70-
_id,
71-
{ $set: { ...company } },
72-
{ new: true }
73-
).exec((err, res) => {
74-
err ? reject(err) : resolve(res);
75-
});
76-
});
68+
const data = await Company.updateOne(
69+
{ _id },
70+
{ ...company },
71+
{ new: true }
72+
).exec();
73+
return data.ok ? true : false;
7774
},
7875
deleteCompany: async (parent, { _id }, context, info) => {
7976
const company = await Company.findById(_id).exec();
8077
if (!company) throw new Error("Company not found.");
8178
if (company.status === 1) throw new Error("Company deleted.");
8279
await Freight.updateMany({ company: _id }, { $set: { status: false } });
83-
return new Promise((resolve, reject) =>
84-
Company.findByIdAndUpdate(_id, { status: 1 }).exec((err, res) => {
85-
err ? reject(err) : resolve(res);
86-
})
87-
);
80+
const update = await Company.updateOne(
81+
{ _id },
82+
{ status: 1 },
83+
{ new: true }
84+
).exec();
85+
return update.ok ? true : false;
8886
}
8987
}
9088
};

graphql/resolvers/Freight/index.js

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -248,27 +248,20 @@ export default {
248248
}
249249
},
250250
updateFreight: async (parent, { _id, freight }, context, info) => {
251-
return new Promise((resolve, reject) => {
252-
Freight.findByIdAndUpdate(
253-
_id,
254-
{ $set: { ...freight } },
255-
{ new: true }
256-
).exec((err, res) => {
257-
err ? reject(err) : resolve(res);
258-
});
259-
});
251+
const update = await Freight.updateOne(
252+
{ _id },
253+
{ $set: { ...freight } },
254+
{ new: true }
255+
).exec();
256+
return update.ok ? true : false;
260257
},
261-
deleteFreight: async (parent, { _id }, context, info) => {
262-
try {
263-
return new Promise((resolve, reject) => {
264-
Freight.findByIdAndDelete(_id).exec((err, res) => {
265-
err ? reject(err) : resolve(res);
266-
});
267-
});
268-
} catch (error) {
269-
console.log(error);
270-
throw error;
271-
}
258+
deleteFreight: async (parent, args, context, info) => {
259+
const update = await Freight.updateOne(
260+
args,
261+
{ status: false },
262+
{ new: true }
263+
).exec();
264+
return update.ok ? true : false;
272265
}
273266
},
274267
Subscription: {

graphql/resolvers/Location/index.js

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@ import {
44
FILTER_CONDITION_TYPE
55
} from "@entria/graphql-mongo-helpers";
66

7-
const stringToRegexQuery = val => {
8-
return { $regex: new RegExp(val) };
9-
};
10-
117
const LocationFilterMapping = {
128
code: {
139
type: FILTER_CONDITION_TYPE.MATCH_1_TO_1
@@ -68,38 +64,5 @@ export default {
6864
}))
6965
};
7066
}
71-
},
72-
Mutation: {
73-
createLocation: async (parent, { location }, context, info) => {
74-
const newLocation = await new Location({
75-
code: location.code,
76-
city: location.city,
77-
state: location.state,
78-
location: location.location
79-
});
80-
return new Promise((resolve, reject) => {
81-
newLocation.save((err, res) => {
82-
err ? reject(err) : resolve(res);
83-
});
84-
});
85-
},
86-
updateLocation: async (parent, { _id, location }, context, info) => {
87-
return new Promise((resolve, reject) => {
88-
Location.findByIdAndUpdate(
89-
_id,
90-
{ $set: { ...location } },
91-
{ new: true }
92-
).exec((err, res) => {
93-
err ? reject(err) : resolve(res);
94-
});
95-
});
96-
},
97-
deleteLocation: async (parent, { _id }, context, info) => {
98-
return new Promise((resolve, reject) => {
99-
Location.findByIdAndDelete(_id).exec((err, res) => {
100-
err ? reject(err) : resolve(res);
101-
});
102-
});
103-
}
10467
}
10568
};

graphql/types/Company/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ export default `
2828
2929
type Mutation {
3030
createCompany(company: CreateCompanyInput!): Company!
31-
updateCompany(_id: String!, company: UpdateCompanyInput!): Company!
32-
deleteCompany(_id: String!): Company!
31+
updateCompany(_id: String!, company: UpdateCompanyInput!): Boolean!
32+
deleteCompany(_id: String!): Boolean!
3333
}
3434
input CreateCompanyInput {
3535
name: String!

graphql/types/Freight/index.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,6 @@ export default `
3232
freights: [Freight!]!
3333
}
3434
35-
input InputFreights {
36-
status: Boolean
37-
origin: UpdateLocationInput
38-
destination: UpdateLocationInput
39-
company: InputFreightCompany
40-
41-
vehicles: [String]
42-
bodies: [String]
43-
}
44-
4535
input InputFreightCompany {
4636
_id: ID
4737
name: String
@@ -55,10 +45,20 @@ export default `
5545
freights(page: Int, perpage: Int, filter: InputFreights): OutputFreight!
5646
}
5747
48+
input InputFreights {
49+
status: Boolean
50+
origin: InputLocation
51+
destination: InputLocation
52+
company: InputFreightCompany
53+
54+
vehicles: [String]
55+
bodies: [String]
56+
}
57+
5858
type Mutation {
5959
createFreight(freight: CreateFreightInput!): Freight!
60-
updateFreight(_id: ID!, freight: UpdateFreightInput!): Freight!
61-
deleteFreight(_id: ID!): Freight!
60+
updateFreight(_id: ID!, freight: UpdateFreightInput!): Boolean!
61+
deleteFreight(_id: ID!): Boolean!
6262
}
6363
6464
input CreateFreightInput {

graphql/types/Location/index.js

Lines changed: 9 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -16,62 +16,26 @@ export default `
1616
coordinates: [Float]!
1717
}
1818
19-
input InputStateOptional {
20-
uf: String
21-
name: String
22-
}
23-
24-
input InputStateRequired {
25-
uf: String!
26-
name: String!
19+
type Query {
20+
location(filter: InputLocation): Location!
21+
locations(page: Int, perpage: Int, filter: InputLocations): OutputLocations
2722
}
2823
29-
input InputQueryLocation {
24+
input InputLocation {
3025
_id: ID
3126
code: String
3227
city: String
3328
state: InputStateOptional
34-
}
35-
36-
input InputQueryLocations {
37-
city: String,
38-
state: InputStateOptional
39-
}
40-
41-
type Query {
42-
location(filter: InputQueryLocation): Location!
43-
locations(page: Int, perpage: Int, filter: InputQueryLocations): OutputLocations
44-
}
45-
46-
type Mutation {
47-
createLocation(location: CreateLocationInput): Location!
48-
updateLocation(_id: ID!, location: UpdateLocationInput): Location!
49-
deleteLocation(_id: ID!): Location!
5029
}
5130
52-
input InputPositionRequired {
53-
type: String!
54-
coordinates: [Float]!
55-
}
56-
57-
input InputPositionOptional {
58-
type: String
59-
coordinates: [Float]!
60-
}
61-
62-
input CreateLocationInput {
63-
code: String!
64-
city: String!
65-
state: InputStateRequired!
66-
location: InputPositionRequired!
31+
input InputStateOptional {
32+
uf: String
33+
name: String
6734
}
6835
69-
input UpdateLocationInput {
70-
_id: ID
71-
code: String
72-
city: String
36+
input InputLocations {
37+
city: String,
7338
state: InputStateOptional
74-
location: InputPositionOptional
7539
}
7640
7741
type OutputLocations {

0 commit comments

Comments
 (0)