-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: basic integration of live page (#170)
* fix: company schema for basic data reads * fix: live schema for basic data reads * fix: typo in LiveDatasources * feat: new SemesterEnum
- Loading branch information
Showing
13 changed files
with
444 additions
and
373 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const { GraphQLEnumType } = require('../scalars'); | ||
|
||
const SemesterEnum = new GraphQLEnumType({ | ||
name: 'SemesterEnum', | ||
values: { | ||
AUTUMN: { value: 0 }, | ||
SPRING: { value: 1 }, | ||
}, | ||
}); | ||
|
||
module.exports = SemesterEnum; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,27 @@ | ||
const { GraphQLObjectType, GraphQLNonNull, GraphQLID, GraphQLString } = require('../scalars'); | ||
const { registerCompany, deleteCompanyById } = require('./company.resolver'); | ||
const CompanyType = require('./company.type'); | ||
const { GraphQLObjectType } = require('../scalars'); | ||
// const { registerCompany, deleteCompanyById } = require('./company.resolver'); | ||
// const CompanyType = require('./company.type'); | ||
|
||
module.exports = new GraphQLObjectType({ | ||
name: 'CompanyMutation', | ||
fields: { | ||
registerCompany: { | ||
type: CompanyType, | ||
description: 'Register a company', | ||
args: { | ||
name: { type: new GraphQLNonNull(GraphQLString) }, | ||
location: { type: new GraphQLNonNull(GraphQLString) }, | ||
logo: { type: new GraphQLNonNull(GraphQLID) }, | ||
}, | ||
resolve: registerCompany, | ||
}, | ||
deleteCompanyById: { | ||
type: CompanyType, | ||
description: 'delete comapny by company ID', | ||
args: { | ||
id: { type: new GraphQLNonNull(GraphQLID) }, | ||
}, | ||
resolve: deleteCompanyById, | ||
}, | ||
// registerCompany: { | ||
// type: CompanyType, | ||
// description: 'Register a company', | ||
// args: { | ||
// name: { type: new GraphQLNonNull(GraphQLString) }, | ||
// location: { type: new GraphQLNonNull(GraphQLString) }, | ||
// logo: { type: new GraphQLNonNull(GraphQLID) }, | ||
// }, | ||
// resolve: registerCompany, | ||
// }, | ||
// deleteCompanyById: { | ||
// type: CompanyType, | ||
// description: 'delete comapny by company ID', | ||
// args: { | ||
// id: { type: new GraphQLNonNull(GraphQLID) }, | ||
// }, | ||
// resolve: deleteCompanyById, | ||
// }, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,36 @@ | ||
const { GraphQLObjectType, GraphQLList, GraphQLNonNull, GraphQLInt, GraphQLID } = require('../scalars'); | ||
const { GraphQLObjectType, GraphQLNonNull, GraphQLID } = require('../scalars'); | ||
const CompanyType = require('./company.type'); | ||
|
||
const { getListOfCompanies, getCompanyById, getCompaniesByIds } = require('./company.resolver'); | ||
const { getCompanyById } = require('./company.resolver'); | ||
|
||
module.exports = new GraphQLObjectType({ | ||
name: 'CompanyQuery', | ||
fields: { | ||
getListOfCompanies: { | ||
description: 'Get list of all companies', | ||
type: new GraphQLList(CompanyType), | ||
args: { | ||
offset: { type: GraphQLInt }, | ||
limit: { type: GraphQLInt }, | ||
}, | ||
resolve: getListOfCompanies, | ||
}, | ||
getCompanyById: { | ||
description: 'Get company by id', | ||
description: 'Get a company by its mongo ID.', | ||
type: CompanyType, | ||
args: { | ||
id: { type: new GraphQLNonNull(GraphQLID) }, | ||
}, | ||
resolve: getCompanyById, | ||
}, | ||
getCompaniesByIds: { | ||
description: 'Get companies by list of ids', | ||
type: GraphQLList(CompanyType), | ||
args: { | ||
ids: { type: new GraphQLNonNull(GraphQLList(GraphQLID)) }, | ||
}, | ||
resolve: getCompaniesByIds, | ||
}, | ||
|
||
// getListOfCompanies: { | ||
// description: 'Get list of all companies', | ||
// type: new GraphQLList(CompanyType), | ||
// args: { | ||
// offset: { type: GraphQLInt }, | ||
// limit: { type: GraphQLInt }, | ||
// }, | ||
// resolve: getListOfCompanies, | ||
// }, | ||
// getCompaniesByIds: { | ||
// description: 'Get companies by list of ids', | ||
// type: GraphQLList(CompanyType), | ||
// args: { | ||
// ids: { type: new GraphQLNonNull(GraphQLList(GraphQLID)) }, | ||
// }, | ||
// resolve: getCompaniesByIds, | ||
// }, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,62 @@ | ||
const { APIError } = require('../../utils/exception'); | ||
const UserPermission = require('../../utils/userAuth/permission'); | ||
// const UserPermission = require('../../utils/userAuth/permission'); | ||
|
||
const DEF_LIMIT = 10; | ||
const DEF_OFFSET = 0; | ||
// const DEF_LIMIT = 10; | ||
// const DEF_OFFSET = 0; | ||
|
||
module.exports = { | ||
deleteCompanyById: async (_parent, { id }, { session, authToken, decodedToken, API: { Company } }) => { | ||
try { | ||
if (!UserPermission.exists(session, authToken, decodedToken, 'live.write.all')) { | ||
throw APIError('FORBIDDEN', null, { | ||
reason: 'The user does not have the required permission to perform this operation.', | ||
}); | ||
} | ||
const company = await Company.deleteById(id); | ||
return company; | ||
} catch (error) { | ||
throw APIError(null, error); | ||
} | ||
}, | ||
getListOfCompanies: async (_parent, { limit = DEF_LIMIT, offset = DEF_OFFSET }, { API: { Company } }) => { | ||
try { | ||
const allCompany = await Company.find({}, limit, offset); | ||
return allCompany; | ||
} catch (error) { | ||
throw APIError(null, error); | ||
} | ||
}, | ||
getCompanyById: async (_parent, { id }, { API: { Company } }) => { | ||
getCompanyById: async (_parent, { id }, { API: { Company } }, _) => { | ||
try { | ||
const _company = await Company.findByID.load(id); | ||
return _company; | ||
} catch (error) { | ||
throw APIError(null, error); | ||
} | ||
}, | ||
getCompaniesByIds: async (_parent, { ids }, { API: { Company } }) => { | ||
try { | ||
const companies = await Company.findByID.load(ids); | ||
return companies; | ||
} catch (error) { | ||
throw APIError(null, error); | ||
} | ||
}, | ||
registerCompany: async ( | ||
_parent, | ||
{ name, location, logo }, | ||
{ mid, session, authToken, decodedToken, API: { Company } } | ||
) => { | ||
try { | ||
if (!UserPermission.exists(session, authToken, decodedToken, 'live.write.all')) { | ||
throw APIError('FORBIDDEN', null, { | ||
reason: 'The user does not have the required permission to perform this operation.', | ||
}); | ||
} | ||
const _company = await Company.create(name, location, logo, session, authToken, mid); | ||
return _company; | ||
} catch (error) { | ||
throw APIError(null, error); | ||
} | ||
}, | ||
// deleteCompanyById: async (_parent, { id }, { session, authToken, decodedToken, API: { Company } }) => { | ||
// try { | ||
// if (!UserPermission.exists(session, authToken, decodedToken, 'live.write.all')) { | ||
// throw APIError('FORBIDDEN', null, { | ||
// reason: 'The user does not have the required permission to perform this operation.', | ||
// }); | ||
// } | ||
// const company = await Company.deleteById(id); | ||
// return company; | ||
// } catch (error) { | ||
// throw APIError(null, error); | ||
// } | ||
// }, | ||
// getListOfCompanies: async (_parent, { limit = DEF_LIMIT, offset = DEF_OFFSET }, { API: { Company } }) => { | ||
// try { | ||
// const allCompany = await Company.find({}, limit, offset); | ||
// return allCompany; | ||
// } catch (error) { | ||
// throw APIError(null, error); | ||
// } | ||
// }, | ||
// getCompaniesByIds: async (_parent, { ids }, { API: { Company } }) => { | ||
// try { | ||
// const companies = await Company.findByID.load(ids); | ||
// return companies; | ||
// } catch (error) { | ||
// throw APIError(null, error); | ||
// } | ||
// }, | ||
// registerCompany: async ( | ||
// _parent, | ||
// { name, location, logo }, | ||
// { mid, session, authToken, decodedToken, API: { Company } } | ||
// ) => { | ||
// try { | ||
// if (!UserPermission.exists(session, authToken, decodedToken, 'live.write.all')) { | ||
// throw APIError('FORBIDDEN', null, { | ||
// reason: 'The user does not have the required permission to perform this operation.', | ||
// }); | ||
// } | ||
// const _company = await Company.create(name, location, logo, session, authToken, mid); | ||
// return _company; | ||
// } catch (error) { | ||
// throw APIError(null, error); | ||
// } | ||
// }, | ||
}; |
Oops, something went wrong.