chore: adds tests to validate queries
This commit is contained in:
16
src/errors/QueryError.ts
Normal file
16
src/errors/QueryError.ts
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
import httpStatus from 'http-status';
|
||||||
|
import type { TFunction } from 'i18next';
|
||||||
|
import APIError from './APIError';
|
||||||
|
|
||||||
|
class QueryError extends APIError {
|
||||||
|
constructor(results: { path: string }[], t?: TFunction) {
|
||||||
|
const message = t ? t('error:unspecific', { count: results.length }) : `The following path${results.length === 1 ? '' : 's'} cannot be queried:`;
|
||||||
|
super(
|
||||||
|
`${message} ${results.map((err) => err.path).join(', ')}`,
|
||||||
|
httpStatus.BAD_REQUEST,
|
||||||
|
results,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default QueryError;
|
||||||
@@ -12,6 +12,7 @@ import { CollectionPermission, FieldPermissions, GlobalPermission } from '../aut
|
|||||||
import flattenFields from '../utilities/flattenTopLevelFields';
|
import flattenFields from '../utilities/flattenTopLevelFields';
|
||||||
import { getEntityPolicies } from '../utilities/getEntityPolicies';
|
import { getEntityPolicies } from '../utilities/getEntityPolicies';
|
||||||
import { SanitizedConfig } from '../config/types';
|
import { SanitizedConfig } from '../config/types';
|
||||||
|
import QueryError from '../errors/QueryError';
|
||||||
|
|
||||||
const validOperators = ['like', 'contains', 'in', 'all', 'not_in', 'greater_than_equal', 'greater_than', 'less_than_equal', 'less_than', 'not_equals', 'equals', 'exists', 'near'];
|
const validOperators = ['like', 'contains', 'in', 'all', 'not_in', 'greater_than_equal', 'greater_than', 'less_than_equal', 'less_than', 'not_equals', 'equals', 'exists', 'near'];
|
||||||
|
|
||||||
@@ -46,8 +47,6 @@ type ParamParserArgs = {
|
|||||||
overrideAccess?: boolean
|
overrideAccess?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
type QueryError = { path: string }
|
|
||||||
|
|
||||||
export class ParamParser {
|
export class ParamParser {
|
||||||
collectionSlug?: string
|
collectionSlug?: string
|
||||||
|
|
||||||
@@ -74,7 +73,7 @@ export class ParamParser {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
errors: QueryError[]
|
errors: { path: string }[]
|
||||||
|
|
||||||
constructor({
|
constructor({
|
||||||
req,
|
req,
|
||||||
@@ -566,7 +565,11 @@ const getBuildQueryPlugin = ({
|
|||||||
overrideAccess,
|
overrideAccess,
|
||||||
});
|
});
|
||||||
const result = await paramParser.parse();
|
const result = await paramParser.parse();
|
||||||
// TODO: throw errors here
|
|
||||||
|
if (this.errors.length > 0) {
|
||||||
|
throw new QueryError(this.errors);
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
modifiedSchema.statics.buildQuery = buildQuery;
|
modifiedSchema.statics.buildQuery = buildQuery;
|
||||||
|
|||||||
@@ -35,6 +35,29 @@ export const customIdNumberSlug = 'custom-id-number';
|
|||||||
export const errorOnHookSlug = 'error-on-hooks';
|
export const errorOnHookSlug = 'error-on-hooks';
|
||||||
|
|
||||||
export default buildConfig({
|
export default buildConfig({
|
||||||
|
endpoints: [
|
||||||
|
{
|
||||||
|
path: '/send-test-email',
|
||||||
|
method: 'get',
|
||||||
|
handler: async (req, res) => {
|
||||||
|
await req.payload.sendEmail({
|
||||||
|
from: 'dev@payloadcms.com',
|
||||||
|
to: devUser.email,
|
||||||
|
subject: 'Test Email',
|
||||||
|
html: 'This is a test email.',
|
||||||
|
// to recreate a failing email transport, add the following credentials
|
||||||
|
// to the `email` property of `payload.init()` in `../dev.ts`
|
||||||
|
// the app should fail to send the email, but the error should be handled without crashing the app
|
||||||
|
// transportOptions: {
|
||||||
|
// host: 'smtp.ethereal.email',
|
||||||
|
// port: 587,
|
||||||
|
// },
|
||||||
|
});
|
||||||
|
|
||||||
|
res.status(200).send('Email sent');
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
collections: [
|
collections: [
|
||||||
{
|
{
|
||||||
slug,
|
slug,
|
||||||
@@ -78,6 +101,13 @@ export default buildConfig({
|
|||||||
relationTo: [relationSlug, 'dummy'],
|
relationTo: [relationSlug, 'dummy'],
|
||||||
hasMany: true,
|
hasMany: true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: 'restrictedField',
|
||||||
|
type: 'text',
|
||||||
|
access: {
|
||||||
|
read: () => false,
|
||||||
|
},
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -91,7 +121,23 @@ export default buildConfig({
|
|||||||
],
|
],
|
||||||
},
|
},
|
||||||
collectionWithName(relationSlug),
|
collectionWithName(relationSlug),
|
||||||
collectionWithName('dummy'),
|
{
|
||||||
|
slug: 'dummy',
|
||||||
|
access: openAccess,
|
||||||
|
fields: [
|
||||||
|
{
|
||||||
|
type: 'text',
|
||||||
|
name: 'title',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'text',
|
||||||
|
name: 'name',
|
||||||
|
access: {
|
||||||
|
read: () => false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
{
|
{
|
||||||
slug: customIdSlug,
|
slug: customIdSlug,
|
||||||
access: openAccess,
|
access: openAccess,
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import mongoose from 'mongoose';
|
|||||||
import { randomBytes } from 'crypto';
|
import { randomBytes } from 'crypto';
|
||||||
import { initPayloadTest } from '../helpers/configHelpers';
|
import { initPayloadTest } from '../helpers/configHelpers';
|
||||||
import type { Relation } from './config';
|
import type { Relation } from './config';
|
||||||
import config, { customIdNumberSlug, customIdSlug, slug, relationSlug, pointSlug, errorOnHookSlug } from './config';
|
import config, { customIdNumberSlug, customIdSlug, errorOnHookSlug, pointSlug, relationSlug, slug } from './config';
|
||||||
import payload from '../../src';
|
import payload from '../../src';
|
||||||
import { RESTClient } from '../helpers/rest';
|
import { RESTClient } from '../helpers/rest';
|
||||||
import type { ErrorOnHook, Post } from './payload-types';
|
import type { ErrorOnHook, Post } from './payload-types';
|
||||||
@@ -49,10 +49,16 @@ describe('collections-rest', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should update existing', async () => {
|
it('should update existing', async () => {
|
||||||
const { id, description } = await createPost({ description: 'desc' });
|
const {
|
||||||
|
id,
|
||||||
|
description,
|
||||||
|
} = await createPost({ description: 'desc' });
|
||||||
const updatedTitle = 'updated-title';
|
const updatedTitle = 'updated-title';
|
||||||
|
|
||||||
const { status, doc: updated } = await client.update<Post>({
|
const {
|
||||||
|
status,
|
||||||
|
doc: updated,
|
||||||
|
} = await client.update<Post>({
|
||||||
id,
|
id,
|
||||||
data: { title: updatedTitle },
|
data: { title: updatedTitle },
|
||||||
});
|
});
|
||||||
@@ -62,98 +68,305 @@ describe('collections-rest', () => {
|
|||||||
expect(updated.description).toEqual(description); // Check was not modified
|
expect(updated.description).toEqual(description); // Check was not modified
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should bulk update', async () => {
|
describe('Bulk operations', () => {
|
||||||
await mapAsync([...Array(11)], async (_, i) => {
|
it('should bulk update', async () => {
|
||||||
await createPost({ description: `desc ${i}` });
|
await mapAsync([...Array(11)], async (_, i) => {
|
||||||
|
await createPost({ description: `desc ${i}` });
|
||||||
|
});
|
||||||
|
|
||||||
|
const description = 'updated';
|
||||||
|
const {
|
||||||
|
status,
|
||||||
|
docs,
|
||||||
|
} = await client.updateMany<Post>({
|
||||||
|
where: { title: { equals: 'title' } },
|
||||||
|
data: { description },
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(status).toEqual(200);
|
||||||
|
expect(docs[0].title).toEqual('title'); // Check was not modified
|
||||||
|
expect(docs[0].description).toEqual(description);
|
||||||
|
expect(docs.pop().description).toEqual(description);
|
||||||
});
|
});
|
||||||
|
|
||||||
const description = 'updated';
|
it('should not bulk update with a bad query', async () => {
|
||||||
const { status, docs } = await client.updateMany<Post>({
|
await mapAsync([...Array(2)], async (_, i) => {
|
||||||
query: { title: { equals: 'title' } },
|
await createPost({ description: `desc ${i}` });
|
||||||
data: { description },
|
});
|
||||||
|
|
||||||
|
const description = 'updated';
|
||||||
|
|
||||||
|
const { status, docs: noDocs, errors } = await client.updateMany<Post>({
|
||||||
|
where: { missing: { equals: 'title' } },
|
||||||
|
data: { description },
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(status).toEqual(400);
|
||||||
|
expect(noDocs).toBeUndefined();
|
||||||
|
expect(errors).toHaveLength(1);
|
||||||
|
|
||||||
|
const { docs } = await payload.find({
|
||||||
|
collection: slug,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(docs[0].description).not.toEqual(description);
|
||||||
|
expect(docs.pop().description).not.toEqual(description);
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(status).toEqual(200);
|
it('should not bulk update with a bad relationship query', async () => {
|
||||||
expect(docs[0].title).toEqual('title'); // Check was not modified
|
await mapAsync([...Array(2)], async (_, i) => {
|
||||||
expect(docs[0].description).toEqual(description);
|
await createPost({ description: `desc ${i}` });
|
||||||
expect(docs.pop().description).toEqual(description);
|
});
|
||||||
});
|
|
||||||
|
|
||||||
it('should return formatted errors for bulk updates', async () => {
|
const description = 'updated';
|
||||||
const text = 'bulk-update-test-errors';
|
const { status: relationFieldStatus, docs: relationFieldDocs, errors: relationFieldErrors } = await client.updateMany<Post>({
|
||||||
const errorDoc = await payload.create({
|
where: { 'relationField.missing': { equals: 'title' } },
|
||||||
collection: errorOnHookSlug,
|
data: { description },
|
||||||
data: {
|
});
|
||||||
text,
|
|
||||||
errorBeforeChange: true,
|
console.log({ relationFieldStatus, relationFieldDocs, relationFieldErrors });
|
||||||
},
|
|
||||||
});
|
const { status: relationMultiRelationToStatus } = await client.updateMany<Post>({
|
||||||
const successDoc = await payload.create({
|
where: { 'relationMultiRelationTo.missing': { equals: 'title' } },
|
||||||
collection: errorOnHookSlug,
|
data: { description },
|
||||||
data: {
|
});
|
||||||
text,
|
|
||||||
errorBeforeChange: false,
|
const { docs } = await payload.find({
|
||||||
},
|
collection: slug,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(relationFieldStatus).toEqual(400);
|
||||||
|
expect(relationMultiRelationToStatus).toEqual(400);
|
||||||
|
expect(docs[0].description).not.toEqual(description);
|
||||||
|
expect(docs.pop().description).not.toEqual(description);
|
||||||
});
|
});
|
||||||
|
|
||||||
const update = 'update';
|
it('should not bulk update with a read restricted field query', async () => {
|
||||||
|
const { id } = await payload.create({
|
||||||
|
collection: slug,
|
||||||
|
data: {
|
||||||
|
restrictedField: 'restricted',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
const result = await client.updateMany<ErrorOnHook>({
|
const description = 'description';
|
||||||
slug: errorOnHookSlug,
|
const { status } = await client.updateMany<Post>({
|
||||||
query: { text: { equals: text } },
|
query: { restrictedField: { equals: 'restricted' } },
|
||||||
data: { text: update },
|
data: { description },
|
||||||
|
});
|
||||||
|
|
||||||
|
const doc = await payload.findByID({
|
||||||
|
collection: slug,
|
||||||
|
id,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(status).toEqual(400);
|
||||||
|
expect(doc.description).toBeUndefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(result.status).toEqual(400);
|
it('should bulk update with a relationship field that exists in one collection and not another', async () => {
|
||||||
expect(result.docs).toHaveLength(1);
|
const relationOne = await payload.create({
|
||||||
expect(result.docs[0].id).toEqual(successDoc.id);
|
collection: 'dummy',
|
||||||
expect(result.errors).toHaveLength(1);
|
data: {
|
||||||
expect(result.errors[0].message).toBeDefined();
|
title: 'title',
|
||||||
expect(result.errors[0].id).toEqual(errorDoc.id);
|
},
|
||||||
expect(result.docs[0].text).toEqual(update);
|
});
|
||||||
});
|
const relationTwo = await payload.create({
|
||||||
|
collection: 'relation',
|
||||||
|
data: {
|
||||||
|
name: 'name',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
it('should bulk delete', async () => {
|
const description = 'desc';
|
||||||
const count = 11;
|
const relationPost = await payload.create({
|
||||||
await mapAsync([...Array(count)], async (_, i) => {
|
collection: slug,
|
||||||
await createPost({ description: `desc ${i}` });
|
data: {
|
||||||
|
description,
|
||||||
|
relationMultiRelationTo: {
|
||||||
|
value: relationTwo.id,
|
||||||
|
relationTo: 'relation',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const relationToDummyPost = await payload.create({
|
||||||
|
collection: slug,
|
||||||
|
data: {
|
||||||
|
description,
|
||||||
|
relationMultiRelationTo: {
|
||||||
|
value: relationOne.id,
|
||||||
|
relationTo: 'dummy',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const updatedDescription = 'updated';
|
||||||
|
|
||||||
|
const { status: relationMultiRelationToStatus, docs: updated } = await client.updateMany<Post>({
|
||||||
|
where: {
|
||||||
|
'relationMultiRelationTo.title': {
|
||||||
|
equals: relationOne.title,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
data: { description: updatedDescription },
|
||||||
|
});
|
||||||
|
|
||||||
|
const updatedDoc = await payload.findByID({
|
||||||
|
collection: slug,
|
||||||
|
id: relationToDummyPost.id,
|
||||||
|
});
|
||||||
|
|
||||||
|
const otherDoc = await payload.findByID({
|
||||||
|
collection: slug,
|
||||||
|
id: relationPost.id,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(relationMultiRelationToStatus).toEqual(200);
|
||||||
|
expect(updated).toHaveLength(1);
|
||||||
|
expect(updated[0].id).toEqual(relationToDummyPost.id);
|
||||||
|
expect(updatedDoc.description).toEqual(updatedDescription);
|
||||||
|
expect(otherDoc.description).toEqual(description);
|
||||||
});
|
});
|
||||||
|
|
||||||
const { status, docs } = await client.deleteMany<Post>({
|
it('should bulk update with a relationship field that exists in one collection and is restricted in another', async () => {
|
||||||
query: { title: { eq: 'title' } },
|
const name = 'name';
|
||||||
|
const relationOne = await payload.create({
|
||||||
|
collection: 'dummy',
|
||||||
|
data: {
|
||||||
|
title: 'title',
|
||||||
|
name, // read access: () => false
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const relationTwo = await payload.create({
|
||||||
|
collection: 'relation',
|
||||||
|
data: {
|
||||||
|
name,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const description = 'desc';
|
||||||
|
const relationPost = await payload.create({
|
||||||
|
collection: slug,
|
||||||
|
data: {
|
||||||
|
description,
|
||||||
|
relationMultiRelationTo: {
|
||||||
|
value: relationTwo.id,
|
||||||
|
relationTo: 'relation',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const relationToDummyPost = await payload.create({
|
||||||
|
collection: slug,
|
||||||
|
data: {
|
||||||
|
description,
|
||||||
|
relationMultiRelationTo: {
|
||||||
|
value: relationOne.id,
|
||||||
|
relationTo: 'dummy',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const updatedDescription = 'updated';
|
||||||
|
|
||||||
|
const { status } = await client.updateMany<Post>({
|
||||||
|
where: { 'relationMultiRelationTo.name': { equals: name } },
|
||||||
|
data: { description: updatedDescription },
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
const updatedDoc = await payload.findByID({
|
||||||
|
collection: slug,
|
||||||
|
id: relationPost.id,
|
||||||
|
});
|
||||||
|
|
||||||
|
const otherDoc = await payload.findByID({
|
||||||
|
collection: slug,
|
||||||
|
id: relationToDummyPost.id,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(status).toEqual(200);
|
||||||
|
expect(updatedDoc.description).toEqual(updatedDescription);
|
||||||
|
expect(otherDoc.description).toEqual(description);
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(status).toEqual(200);
|
it('should return formatted errors for bulk updates', async () => {
|
||||||
expect(docs[0].title).toEqual('title'); // Check was not modified
|
const text = 'bulk-update-test-errors';
|
||||||
expect(docs).toHaveLength(count);
|
const errorDoc = await payload.create({
|
||||||
});
|
collection: errorOnHookSlug,
|
||||||
|
data: {
|
||||||
|
text,
|
||||||
|
errorBeforeChange: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const successDoc = await payload.create({
|
||||||
|
collection: errorOnHookSlug,
|
||||||
|
data: {
|
||||||
|
text,
|
||||||
|
errorBeforeChange: false,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
it('should return formatted errors for bulk deletes', async () => {
|
const update = 'update';
|
||||||
await payload.create({
|
|
||||||
collection: errorOnHookSlug,
|
const result = await client.updateMany<ErrorOnHook>({
|
||||||
data: {
|
slug: errorOnHookSlug,
|
||||||
text: 'test',
|
where: { text: { equals: text } },
|
||||||
errorAfterDelete: true,
|
data: { text: update },
|
||||||
},
|
});
|
||||||
});
|
|
||||||
await payload.create({
|
expect(result.status).toEqual(400);
|
||||||
collection: errorOnHookSlug,
|
expect(result.docs).toHaveLength(1);
|
||||||
data: {
|
expect(result.docs[0].id).toEqual(successDoc.id);
|
||||||
text: 'test',
|
expect(result.errors).toHaveLength(1);
|
||||||
errorAfterDelete: false,
|
expect(result.errors[0].message).toBeDefined();
|
||||||
},
|
expect(result.errors[0].id).toEqual(errorDoc.id);
|
||||||
|
expect(result.docs[0].text).toEqual(update);
|
||||||
});
|
});
|
||||||
|
|
||||||
const result = await client.deleteMany({
|
it('should bulk delete', async () => {
|
||||||
slug: errorOnHookSlug,
|
const count = 11;
|
||||||
query: { text: { equals: 'test' } },
|
await mapAsync([...Array(count)], async (_, i) => {
|
||||||
|
await createPost({ description: `desc ${i}` });
|
||||||
|
});
|
||||||
|
|
||||||
|
const { status, docs } = await client.deleteMany<Post>({
|
||||||
|
where: { title: { eq: 'title' } },
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(status).toEqual(200);
|
||||||
|
expect(docs[0].title).toEqual('title'); // Check was not modified
|
||||||
|
expect(docs).toHaveLength(count);
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(result.status).toEqual(400);
|
it('should return formatted errors for bulk deletes', async () => {
|
||||||
expect(result.docs).toHaveLength(1);
|
await payload.create({
|
||||||
expect(result.errors).toHaveLength(1);
|
collection: errorOnHookSlug,
|
||||||
expect(result.errors[0].message).toBeDefined();
|
data: {
|
||||||
expect(result.errors[0].id).toBeDefined();
|
text: 'test',
|
||||||
|
errorAfterDelete: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
await payload.create({
|
||||||
|
collection: errorOnHookSlug,
|
||||||
|
data: {
|
||||||
|
text: 'test',
|
||||||
|
errorAfterDelete: false,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const result = await client.deleteMany({
|
||||||
|
slug: errorOnHookSlug,
|
||||||
|
where: { text: { equals: 'test' } },
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(result.status).toEqual(400);
|
||||||
|
expect(result.docs).toHaveLength(1);
|
||||||
|
expect(result.errors).toHaveLength(1);
|
||||||
|
expect(result.errors[0].message).toBeDefined();
|
||||||
|
expect(result.errors[0].id).toBeDefined();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Custom ID', () => {
|
describe('Custom ID', () => {
|
||||||
@@ -342,7 +555,24 @@ describe('collections-rest', () => {
|
|||||||
expect(result.totalDocs).toEqual(1);
|
expect(result.totalDocs).toEqual(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it.todo('nested by property value');
|
it('nested by property value', async () => {
|
||||||
|
const post1 = await createPost({
|
||||||
|
relationMultiRelationTo: { relationTo: relationSlug, value: relation.id },
|
||||||
|
});
|
||||||
|
await createPost();
|
||||||
|
|
||||||
|
const { status, result } = await client.find<Post>({
|
||||||
|
query: {
|
||||||
|
'relationMultiRelationTo.value.name': {
|
||||||
|
equals: relation.name,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(status).toEqual(200);
|
||||||
|
expect(result.docs).toEqual([post1]);
|
||||||
|
expect(result.totalDocs).toEqual(1);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('relationTo multi hasMany', () => {
|
describe('relationTo multi hasMany', () => {
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ type UpdateManyArgs<T = any> = {
|
|||||||
slug?: string;
|
slug?: string;
|
||||||
data: Partial<T>;
|
data: Partial<T>;
|
||||||
auth?: boolean;
|
auth?: boolean;
|
||||||
query: any;
|
where: any;
|
||||||
};
|
};
|
||||||
|
|
||||||
type DeleteArgs = {
|
type DeleteArgs = {
|
||||||
@@ -69,7 +69,7 @@ type DeleteArgs = {
|
|||||||
type DeleteManyArgs = {
|
type DeleteManyArgs = {
|
||||||
slug?: string;
|
slug?: string;
|
||||||
auth?: boolean;
|
auth?: boolean;
|
||||||
query: any;
|
where: any;
|
||||||
};
|
};
|
||||||
|
|
||||||
type FindGlobalArgs<T = any> = {
|
type FindGlobalArgs<T = any> = {
|
||||||
@@ -92,7 +92,7 @@ type DocResponse<T> = {
|
|||||||
type DocsResponse<T> = {
|
type DocsResponse<T> = {
|
||||||
status: number;
|
status: number;
|
||||||
docs: T[];
|
docs: T[];
|
||||||
errors?: { name: string, message: string, data: any, id: string | number}[]
|
errors?: { name: string, message: string, data: any, id: string | number }[]
|
||||||
};
|
};
|
||||||
|
|
||||||
const headers = {
|
const headers = {
|
||||||
@@ -205,9 +205,9 @@ export class RESTClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async updateMany<T = any>(args: UpdateManyArgs<T>): Promise<DocsResponse<T>> {
|
async updateMany<T = any>(args: UpdateManyArgs<T>): Promise<DocsResponse<T>> {
|
||||||
const { slug, data, query } = args;
|
const { slug, data, where } = args;
|
||||||
const formattedQs = qs.stringify({
|
const formattedQs = qs.stringify({
|
||||||
...(query ? { where: query } : {}),
|
...(where ? { where } : {}),
|
||||||
}, {
|
}, {
|
||||||
addQueryPrefix: true,
|
addQueryPrefix: true,
|
||||||
});
|
});
|
||||||
@@ -225,9 +225,9 @@ export class RESTClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async deleteMany<T = any>(args: DeleteManyArgs): Promise<DocsResponse<T>> {
|
async deleteMany<T = any>(args: DeleteManyArgs): Promise<DocsResponse<T>> {
|
||||||
const { slug, query } = args;
|
const { slug, where } = args;
|
||||||
const formattedQs = qs.stringify({
|
const formattedQs = qs.stringify({
|
||||||
...(query ? { where: query } : {}),
|
...(where ? { where } : {}),
|
||||||
}, {
|
}, {
|
||||||
addQueryPrefix: true,
|
addQueryPrefix: true,
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user