mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-25 12:44:07 -08:00
61e26804ba
* ⚡ enabled array-type * ⚡ await-thenable on * ⚡ ban-types on * ⚡ default-param-last on * ⚡ dot-notation on * ⚡ member-delimiter-style on * ⚡ no-duplicate-imports on * ⚡ no-empty-interface on * ⚡ no-floating-promises on * ⚡ no-for-in-array on * ⚡ no-invalid-void-type on * ⚡ no-loop-func on * ⚡ no-shadow on * ⚡ ban-ts-comment re enabled * ⚡ @typescript-eslint/lines-between-class-members on * address my own comment * @typescript-eslint/return-await on * @typescript-eslint/promise-function-async on * @typescript-eslint/no-unnecessary-boolean-literal-compare on * @typescript-eslint/no-unnecessary-type-assertion on * prefer-const on * @typescript-eslint/prefer-optional-chain on Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in>
87 lines
2 KiB
TypeScript
87 lines
2 KiB
TypeScript
import { IExecuteFunctions, IExecuteSingleFunctions, ILoadOptionsFunctions } from 'n8n-core';
|
|
import { IDataObject, jsonParse } from 'n8n-workflow';
|
|
import { ICollection } from './CollectionInterface';
|
|
import { cockpitApiRequest } from './GenericFunctions';
|
|
|
|
export async function createCollectionEntry(
|
|
this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions,
|
|
resourceName: string,
|
|
data: IDataObject,
|
|
id?: string,
|
|
): Promise<any> {
|
|
const body: ICollection = {
|
|
data,
|
|
};
|
|
|
|
if (id) {
|
|
body.data = {
|
|
_id: id,
|
|
...body.data,
|
|
};
|
|
}
|
|
|
|
return cockpitApiRequest.call(this, 'post', `/collections/save/${resourceName}`, body);
|
|
}
|
|
|
|
export async function getAllCollectionEntries(
|
|
this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions,
|
|
resourceName: string,
|
|
options: IDataObject,
|
|
): Promise<any> {
|
|
const body: ICollection = {};
|
|
|
|
if (options.fields) {
|
|
const fields = (options.fields as string).split(',').map((field) => field.trim());
|
|
|
|
const bodyFields = {
|
|
_id: false,
|
|
} as IDataObject;
|
|
for (const field of fields) {
|
|
bodyFields[field] = true;
|
|
}
|
|
|
|
body.fields = bodyFields;
|
|
}
|
|
|
|
if (options.filter) {
|
|
body.filter = jsonParse(options.filter.toString(), {
|
|
errorMessage: "'Filter' option is not valid JSON",
|
|
});
|
|
}
|
|
|
|
if (options.limit) {
|
|
body.limit = options.limit as number;
|
|
}
|
|
|
|
if (options.skip) {
|
|
body.skip = options.skip as number;
|
|
}
|
|
|
|
if (options.sort) {
|
|
body.sort = jsonParse(options.sort.toString(), {
|
|
errorMessage: "'Sort' option is not valid JSON",
|
|
});
|
|
}
|
|
|
|
if (options.populate) {
|
|
body.populate = options.populate as boolean;
|
|
}
|
|
|
|
body.simple = true;
|
|
if (options.rawData) {
|
|
body.simple = !options.rawData;
|
|
}
|
|
|
|
if (options.language) {
|
|
body.lang = options.language as string;
|
|
}
|
|
|
|
return cockpitApiRequest.call(this, 'post', `/collections/get/${resourceName}`, body);
|
|
}
|
|
|
|
export async function getAllCollectionNames(
|
|
this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions,
|
|
): Promise<string[]> {
|
|
return cockpitApiRequest.call(this, 'GET', `/collections/listCollections`, {});
|
|
}
|