Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added resolvers and modified typeDfs #61

Merged
merged 3 commits into from
Jan 23, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
65 changes: 65 additions & 0 deletions src/resolvers/Appointment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { ApolloError, UserInputError } from "apollo-server-express";
import Appointment from "../models/Appointment";

const AppointmentResolver = {
Query: {
appointments: async(root, { filter } , context, info) => {
if (!filter){
throw new UserInputError("No filter provided");
}
const filteredAppointments = await Appointment.find(JSON.parse(filter));
eunicechy marked this conversation as resolved.
Show resolved Hide resolved
return filteredAppointments;
},
appointment: async (root, { id }, context, info) => {
const invalid_input = id.length === 0;
if (invalid_input) {
throw new UserInputError("Invalid ID number provided");
}
const appointment = await Appointment.findById(id);
return appointment;
}
},
Mutation: {
async createAppointment(_, {appointmentInput}) {
if (appointmentInput === null) {
throw new ApolloError("Invalid input for new Appointment");
}
const newAppointment = new Appointment({
...appointmentInput,
});
const appointment = await newAppointment.save();
return appointment;
},
async updateAppointment(_, {appointmentInput}) {
if(!appointmentInput.id) {
throw new UserInputError("Unable to update Appointment with invalid id");
}
try{
return await Appointment.findByIdAndUpdate(appointmentInput.id, {
AppointmentDate: appointmentInput.AppointmentDate,
CustomerID: appointmentInput.CustomerID,
BranchID: appointmentInput.BranchID,
VehicleID: appointmentInput.VehicleID,
ServiceID: appointmentInput.ServiceID,
AppointmentStatus: appointmentInput.AppointmentStatus
eunicechy marked this conversation as resolved.
Show resolved Hide resolved
}, {new: true})
} catch (err) {
throw new ApolloError(err);
}

},
async deleteAppointment(_, { id } ) {
LUXIANZE marked this conversation as resolved.
Show resolved Hide resolved
if(!id){
throw new UserInputError ("Unable to delete Appointment");
}
const appointment = Appointment.findById(id);
if (appointment){
Appointment.findByIdAndRemove(id, () => {});
eunicechy marked this conversation as resolved.
Show resolved Hide resolved
return "Appointment deleted.";
} else {
throw new UserInputError ("Appointment ID is not found.");
}
},
} ,
};
export default AppointmentResolver;
73 changes: 73 additions & 0 deletions src/resolvers/AudioStorage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { ApolloError, UserInputError } from "apollo-server-express";
import AudioStorage from "../models/AudioStorage";

const AudioStorageResolver = {
Query: {
audioUploads:(_,args) => {},
LUXIANZE marked this conversation as resolved.
Show resolved Hide resolved
audioStorages: async (root, { filter } , context, info) => {
if (!filter){
throw new UserInputError("No filter provided");
}
const filteredAudioStorages =await AudioStorage.find(JSON.parse(filter))
eunicechy marked this conversation as resolved.
Show resolved Hide resolved
return filteredAudioStorages;
},
audioStorage: async (root, { id }, context, info) => {
const invalid_input = id.length === 0;
if (invalid_input) {
throw new UserInputError("Invalid ID number provided");
}
const audioStorage = await AudioStorage.findById(id);
return audioStorage;
}
},
Mutation: {
async createAudioStorage(_, {audioStorageInput}) {
if (audioStorageInput === null) {
throw new ApolloError("Invalid input for new AudioStorage");
}
const newAudioStorage = new AudioStorage({
...audioStorageInput,
});
const audioStorage = await newAudioStorage.save();
return audioStorage;
},
async updateAudioStorage(_, {audioStorageInput}) {
if(audioStorageInput.id === null) {
throw new UserInputError("Unable to update AudioStorage with invalid id");
}
try{
return await AudioStorage.findByIdAndUpdate(audioStorageInput.id, {
id: audioStorageInput.id,
audioContent: audioStorageInput.audioContent,
audioURL: audioStorageInput.audioURL,
audioType: audioStorageInput.audioType,
audioLength: audioStorageInput.audioLength,
AudioStorageStatus: audioStorageInput.AudioStorageStatus
}, {new: true})
} catch (err) {
throw new ApolloError(err);
eunicechy marked this conversation as resolved.
Show resolved Hide resolved
}

},
uploadAudioStorage: (_,args) => {
return args.file.then(file =>{
//Contents of Upload scalar: https://github.com/jaydenseric/graphql-upload#class-graphqlupload
//file.createReadStream() is a readable node stream that contains the contents of the uploaded file
return file;
})
},
async deleteAudioStorage(_, { id } ) {
if(!id){
throw new UserInputError ("Unable to delete AudioStorage");
}
const audioStorage = AudioStorage.findById(id);
if (audioStorage){
AudioStorage.findByIdAndRemove(id, () => {});
eunicechy marked this conversation as resolved.
Show resolved Hide resolved
return "AudioStorage deleted.";
} else {
throw new UserInputError ("AudioStorage ID is not found.");
}
},
} ,
};
export default AudioStorageResolver;
71 changes: 71 additions & 0 deletions src/resolvers/Branch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { ApolloError, UserInputError } from "apollo-server-express";
import Branch from "../models/Branch";

const BranchResolver = {
Query: {
branches: async(root, { filter } , context, info) => {
if (!filter){
throw new UserInputError("No filter provided");
}
const filteredBranchs = await Branch.find(JSON.parse(filter));
return filteredBranchs;
},
branch: async (root, { id }, context, info) => {
const invalid_input = id.length === 0;
if (invalid_input) {
throw new UserInputError("Invalid ID number provided");
}
const branch = await Branch.findById(id);
return branch;
}
},
Mutation: {
async createBranch(_, {branchInput}) {
if (branchInput === null) {
throw new ApolloError("Invalid input for new Branch");
}
const newBranch = new Branch({
...branchInput,
});
const branch = await newBranch.save();
return branch
.populate("businesshours")
.populate("services")
.execPopulate();
},
async updateBranch(_, {branchInput}) {
if(!branchInput.id) {
throw new UserInputError("Unable to update Branch with invalid id");
}
try{
let branch = await Branch.findByIdAndUpdate(branchInput.id, {
...branchInput,
}, {new: true}).then (res => { return res; })
return branch
.populate("businesshours")
.populate("services")
.execPopulate();
} catch (err) {
throw new ApolloError(err.message);
}

},
async deleteBranch(_, { id } ) {
if(!id){
throw new UserInputError ("Unable to delete Branch");
}
try{
const branch = Branch.findById(id);
if (branch){
Branch.findByIdAndRemove(id, () => {});
return "Branch deleted.";
} else {
throw new UserInputError ("Branch ID is not found.");
}
}catch (err){
throw new ApolloError(err.message);
}
}
} ,
};
export default BranchResolver;
64 changes: 64 additions & 0 deletions src/resolvers/Company.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { ApolloError, UserInputError } from "apollo-server-express";
import Company from "../models/Company";

const CompanyResolver = {
Query: {
companies: async(root, { filter } , context, info) => {
if (!filter){
throw new UserInputError("No filter provided");
}
const filteredCompanies = await Company.find(JSON.parse(filter));
return filteredCompanies;
},
company: async (root, { id }, context, info) => {
const invalid_input = id.length === 0;
if (invalid_input) {
throw new UserInputError("Invalid ID number provided");
}
LUXIANZE marked this conversation as resolved.
Show resolved Hide resolved
const company = await Company.findById(id);
return company;
}
},
Mutation: {
async createCompany(_, {companyInput}) {
LUXIANZE marked this conversation as resolved.
Show resolved Hide resolved
if (companyInput === null) {
throw new ApolloError("Invalid input for new Company");
}
const newCompany = new Company({
...companyInput,
});
const company = await newCompany.save();
return company;
},
async updateCompany(_, {companyInput}) {
if(!companyInput.id) {
throw new UserInputError("Unable to update Company with invalid id");
}
try{
return await Company.findByIdAndUpdate(companyInput.id, {
...companyInput
}, {new: true})
} catch (err) {
throw new ApolloError(err.message);
}

},
async deleteCompany(_, { id } ) {
if(!id){
throw new UserInputError ("Invalid ID unable to delete Company");
}
try{
const company = await Company.findById(id);
if (company){
Company.findByIdAndRemove(id, () => {});
return "Company deleted.";
} else {
throw new UserInputError ("Company ID is not found.");
}
} catch(err){
throw new ApolloError(err.message);
}
},
} ,
};
export default CompanyResolver;
7 changes: 7 additions & 0 deletions src/resolvers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,18 @@ import ConversationResolver from "./Conversation";
import MessageResolver from "./Message";
import UserResolver from "./User";
import DispatchServiceResolver from "./DispatchService";
import AppointmentResolver from "./Appointment";
import AudioStorageResolver from "./AudioStorage";
import BranchResolver from "./Branch";

export default [
ImageStorageResolver,
MessageResolver,
ConversationResolver,
UserResolver,
DispatchServiceResolver,
AppointmentResolver,
AudioStorageResolver,
BranchResolver,
];

2 changes: 1 addition & 1 deletion src/typeDefs/Appointment.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default gql`
extend type Mutation {
createAppointment(appointmentInput: AppointmentInput!): Appointment!
updateAppointment(appointmentInput: AppointmentInput!): Appointment!
deleteAppointment(appointmentId: String!): Appointment!
deleteAppointment(id: String!): String!
}

input AppointmentInput {
Expand Down
12 changes: 7 additions & 5 deletions src/typeDefs/AudioStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import { gql } from "apollo-server-express";

export default gql`

scalar byteArray

extend type Query {
audioStorages(filter: String!): [AudioStorage!]!
audioStorage(id: ID!): AudioStorage!
Expand All @@ -13,26 +11,30 @@ export default gql`
extend type Mutation {
createAudioStorage(audioStorageInput: AudioStorageInput!): AudioStorage!
updateAudioStorage(audioStorageInput: AudioStorageInput!): AudioStorage!
deleteAudioStorage(audioStorageId: String!): AudioStorage!
deleteAudioStorage(id: String!): String!
uploadAudioStorage(audioStorage: Upload!): AudioStorage!
}

input AudioStorageInput {
id: ID!
audioContent: byteArray
""" audio Content should be Buffer """
audioContent: String!
audioURL: String!
audioType: String!
audioLength: Float
""" upload File properties """
mimetype: String!
encoding: String!
}

type AudioStorage {
id: ID!
audioContent: byteArray
""" should be Buffer """
audioContent: String
audioURL: String!
audioType: String!
audioLength: Float
""" upload File properties """
mimetype: String!
encoding: String!
}
Expand Down
2 changes: 1 addition & 1 deletion src/typeDefs/Branch.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default gql`
extend type Mutation {
createBranch(branchInput: BranchInput!): Branch!
updateBranch(branchInput: BranchInput!): Branch!
deleteBranch(branchId: String!): Branch!
deleteBranch(id: String!): String!
}

input BranchInput {
Expand Down
3 changes: 2 additions & 1 deletion src/typeDefs/Company.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ import { gql } from "apollo-server-express";

export default gql`
extend type Query {
companies(filter: String!): Company!
company(id: ID!): Company!
}

extend type Mutation {
createCompany(companyInput: CompanyInput!): Company!
updateCompany(companyInput: CompanyInput!): Company!
deleteCompany(companyId: String!): Company!
deleteCompany(id: String!): String!
}

input CompanyInput {
Expand Down