convert src/collections

This commit is contained in:
Elliot DeNolf
2020-11-20 14:54:47 -05:00
parent 8d1856ae2d
commit 59e5a73e49
23 changed files with 62 additions and 84 deletions

View File

@@ -5,4 +5,4 @@ const bindCollectionMiddleware = (collection) => {
};
};
module.exports = bindCollectionMiddleware;
export default bindCollectionMiddleware;

View File

@@ -16,4 +16,4 @@ const buildCollectionSchema = (collection, config, schemaOptions = {}) => {
return schema;
};
module.exports = buildCollectionSchema;
export default buildCollectionSchema;

View File

@@ -1,19 +1,8 @@
const {
DateTimeResolver,
} = require('graphql-scalars');
import { DateTimeResolver } from 'graphql-scalars';
import { GraphQLString, GraphQLObjectType, GraphQLBoolean, GraphQLNonNull, GraphQLInt } from 'graphql';
const {
GraphQLString,
GraphQLObjectType,
GraphQLBoolean,
GraphQLNonNull,
GraphQLInt,
} = require('graphql');
const formatName = require('../../graphql/utilities/formatName');
const buildPaginatedListType = require('../../graphql/schema/buildPaginatedListType');
import formatName from '../../graphql/utilities/formatName';
import buildPaginatedListType from '../../graphql/schema/buildPaginatedListType';
function registerCollections() {
const {

View File

@@ -1,6 +1,6 @@
/* eslint-disable no-param-reassign */
function create(collection) {
export default function create(collection) {
async function resolver(_, args, context) {
if (args.locale) {
context.req.locale = args.locale;
@@ -20,5 +20,3 @@ function create(collection) {
const createResolver = resolver.bind(this);
return createResolver;
}
module.exports = create;

View File

@@ -1,5 +1,5 @@
/* eslint-disable no-param-reassign */
function getDeleteResolver(collection) {
export default function getDeleteResolver(collection) {
async function resolver(_, args, context) {
if (args.locale) context.req.locale = args.locale;
if (args.fallbackLocale) context.req.fallbackLocale = args.fallbackLocale;
@@ -18,5 +18,3 @@ function getDeleteResolver(collection) {
const deleteResolver = resolver.bind(this);
return deleteResolver;
}
module.exports = getDeleteResolver;

View File

@@ -1,5 +1,5 @@
/* eslint-disable no-param-reassign */
function find(collection) {
export default function find(collection) {
async function resolver(_, args, context) {
if (args.locale) context.req.locale = args.locale;
if (args.fallbackLocale) context.req.fallbackLocale = args.fallbackLocale;
@@ -20,5 +20,3 @@ function find(collection) {
const findResolver = resolver.bind(this);
return findResolver;
}
module.exports = find;

View File

@@ -1,5 +1,5 @@
/* eslint-disable no-param-reassign */
function findByID(collection) {
export default function findByID(collection) {
async function resolver(_, args, context) {
if (args.locale) context.req.locale = args.locale;
if (args.fallbackLocale) context.req.fallbackLocale = args.fallbackLocale;
@@ -18,5 +18,3 @@ function findByID(collection) {
const findByIDResolver = resolver.bind(this);
return findByIDResolver;
}
module.exports = findByID;

View File

@@ -1,6 +1,6 @@
/* eslint-disable no-param-reassign */
function update(collection) {
export default function update(collection) {
async function resolver(_, args, context) {
if (args.locale) context.req.locale = args.locale;
if (args.fallbackLocale) context.req.fallbackLocale = args.fallbackLocale;
@@ -21,5 +21,3 @@ function update(collection) {
const updateResolver = resolver.bind(this);
return updateResolver;
}
module.exports = update;

View File

@@ -1,4 +1,4 @@
async function create(options) {
export default async function create(options) {
const {
collection: collectionSlug,
depth,
@@ -29,5 +29,3 @@ async function create(options) {
},
});
}
module.exports = create;

View File

@@ -1,4 +1,4 @@
async function localDelete(options) {
export default async function localDelete(options) {
const {
collection: collectionSlug,
depth,
@@ -27,5 +27,3 @@ async function localDelete(options) {
},
});
}
module.exports = localDelete;

View File

@@ -1,4 +1,4 @@
async function find(options) {
export default async function find(options) {
const {
collection: collectionSlug,
depth,
@@ -31,5 +31,3 @@ async function find(options) {
},
});
}
module.exports = find;

View File

@@ -1,4 +1,4 @@
async function findByID(options) {
export default async function findByID(options) {
const {
collection: collectionSlug,
depth,
@@ -29,5 +29,3 @@ async function findByID(options) {
},
});
}
module.exports = findByID;

View File

@@ -1,10 +1,10 @@
const find = require('./find');
const findByID = require('./findByID');
const create = require('./create');
const update = require('./update');
const localDelete = require('./delete');
import find from './find';
import findByID from './findByID';
import create from './create';
import update from './update';
import localDelete from './delete';
const authOperations = require('../../../auth/operations/local');
import authOperations from '../../../auth/operations/local';
module.exports = {
find,

View File

@@ -1,4 +1,4 @@
async function update(options) {
export default async function update(options) {
const {
collection: collectionSlug,
depth,
@@ -31,5 +31,3 @@ async function update(options) {
return this.operations.collections.update(args);
}
module.exports = update;

View File

@@ -1,7 +1,7 @@
const httpStatus = require('http-status');
const formatSuccessResponse = require('../../express/responses/formatSuccess');
import httpStatus from 'http-status';
import formatSuccessResponse from '../../express/responses/formatSuccess';
async function create(req, res, next) {
export default async function create(req, res, next) {
try {
const doc = await this.operations.collections.create({
req,
@@ -18,5 +18,3 @@ async function create(req, res, next) {
return next(error);
}
}
module.exports = create;

View File

@@ -1,7 +1,7 @@
const httpStatus = require('http-status');
const { NotFound } = require('../../errors');
import httpStatus from 'http-status';
import { NotFound } from '../../errors';
async function deleteHandler(req, res, next) {
export default async function deleteHandler(req, res, next) {
try {
const doc = await this.operations.collections.delete({
req,
@@ -19,5 +19,3 @@ async function deleteHandler(req, res, next) {
return next(error);
}
}
module.exports = deleteHandler;

View File

@@ -1,6 +1,6 @@
const httpStatus = require('http-status');
import httpStatus from 'http-status';
async function find(req, res, next) {
export default async function find(req, res, next) {
try {
const options = {
req,
@@ -19,5 +19,3 @@ async function find(req, res, next) {
return next(error);
}
}
module.exports = find;

View File

@@ -1,4 +1,4 @@
async function findByID(req, res, next) {
export default async function findByID(req, res, next) {
const options = {
req,
collection: req.collection,
@@ -13,5 +13,3 @@ async function findByID(req, res, next) {
return next(error);
}
}
module.exports = findByID;

View File

@@ -1,7 +1,7 @@
const httpStatus = require('http-status');
const formatSuccessResponse = require('../../express/responses/formatSuccess');
import httpStatus from 'http-status';
import formatSuccessResponse from '../../express/responses/formatSuccess';
async function update(req, res, next) {
export default async function update(req, res, next) {
try {
const doc = await this.operations.collections.update({
req,
@@ -19,5 +19,3 @@ async function update(req, res, next) {
return next(error);
}
}
module.exports = update;

View File

@@ -1,4 +1,4 @@
function formatRefPathLocales(schema, parentSchema, parentPath) {
export default function formatRefPathLocales(schema, parentSchema, parentPath) {
// Loop through all refPaths within schema
schema.eachPath((pathname, schemaType) => {
// If a dynamic refPath is found
@@ -48,5 +48,3 @@ function formatRefPathLocales(schema, parentSchema, parentPath) {
}
});
}
export default formatRefPathLocales;