Resolve merge conflicts
This commit is contained in:
13
src/index.js
13
src/index.js
@@ -9,6 +9,7 @@ import fileUpload from 'express-fileupload';
|
||||
import mediaRoutes from './routes/Media.routes';
|
||||
import config from '../demo/payload.config';
|
||||
import locale from './middleware/locale';
|
||||
import expressGraphQL from 'express-graphql';
|
||||
|
||||
module.exports = {
|
||||
init: options => {
|
||||
@@ -54,7 +55,17 @@ module.exports = {
|
||||
options.app.use(methodOverride('X-HTTP-Method-Override'));
|
||||
options.app.use(express.urlencoded({ extended: true }));
|
||||
options.app.use(bodyParser.urlencoded({ extended: true }));
|
||||
options.app.use(locale(config.localization));
|
||||
options.app.use(locale(options.config.localization));
|
||||
options.app.use(options.router);
|
||||
|
||||
if (options.config.graphQL && options.graphQLSchema) {
|
||||
options.app.use(
|
||||
options.config.graphQL.path,
|
||||
expressGraphQL({
|
||||
schema: options.graphQLSchema,
|
||||
graphiql: options.config.graphQL.graphiql,
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,20 +1,18 @@
|
||||
import httpStatus from 'http-status';
|
||||
import { modelById } from '../resolvers';
|
||||
|
||||
const findOne = (req, res) => {
|
||||
req.model.findOne({ _id: req.params._id }, (err, doc) => {
|
||||
if (err)
|
||||
return res.status(httpStatus.INTERNAL_SERVER_ERROR).json({ error: err });
|
||||
|
||||
if (!doc)
|
||||
return res.status(httpStatus.NOT_FOUND).send('Not Found');
|
||||
const query = {
|
||||
Model: req.model,
|
||||
id: req.params._id,
|
||||
locale: req.locale,
|
||||
fallback: req.query['fallback-locale']
|
||||
}
|
||||
|
||||
if (req.locale) {
|
||||
doc.setLocale(req.locale, req.query['fallback-locale']);
|
||||
return res.json(doc.toJSON({ virtuals: true }));
|
||||
}
|
||||
|
||||
return res.json(doc);
|
||||
});
|
||||
modelById(query)
|
||||
.then(doc => res.json(doc))
|
||||
.catch(err => res.status(httpStatus.INTERNAL_SERVER_ERROR).json({ error: err }));
|
||||
};
|
||||
|
||||
export default findOne;
|
||||
|
||||
5
src/resolvers/index.js
Normal file
5
src/resolvers/index.js
Normal file
@@ -0,0 +1,5 @@
|
||||
import modelById from './modelById';
|
||||
|
||||
export {
|
||||
modelById
|
||||
}
|
||||
23
src/resolvers/modelById.js
Normal file
23
src/resolvers/modelById.js
Normal file
@@ -0,0 +1,23 @@
|
||||
const modelById = query => {
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
query.Model.findOne({ _id: query.id }, (err, doc) => {
|
||||
|
||||
if (err || !doc) {
|
||||
return reject({ message: 'not found' })
|
||||
}
|
||||
|
||||
let result = doc;
|
||||
|
||||
if (query.locale) {
|
||||
doc.setLocale(query.locale, query.fallback);
|
||||
const json = doc.toJSON({ virtuals: true });
|
||||
result = json;
|
||||
}
|
||||
|
||||
resolve(result);
|
||||
})
|
||||
})
|
||||
};
|
||||
|
||||
export default modelById;
|
||||
Reference in New Issue
Block a user