mirror of
https://github.com/n8n-io/n8n.git
synced 2025-02-21 02:56:40 -08:00
⚡ Minor improvements to Strapi-Node
This commit is contained in:
parent
73e1399c42
commit
c15637a0a8
|
@ -19,9 +19,7 @@ export async function strapiApiRequest(this: IExecuteFunctions | ILoadOptionsFun
|
|||
|
||||
try {
|
||||
const options: OptionsWithUri = {
|
||||
headers: {
|
||||
'Authorization': `Bearer ${qs.jwt}`,
|
||||
},
|
||||
headers: {},
|
||||
method,
|
||||
body,
|
||||
qs,
|
||||
|
@ -34,7 +32,6 @@ export async function strapiApiRequest(this: IExecuteFunctions | ILoadOptionsFun
|
|||
if (Object.keys(body).length === 0) {
|
||||
delete options.body;
|
||||
}
|
||||
delete qs.jwt;
|
||||
|
||||
//@ts-ignore
|
||||
return await this.helpers?.request(options);
|
||||
|
@ -74,7 +71,7 @@ export async function getToken(this: IExecuteFunctions | ILoadOptionsFunctions |
|
|||
return this.helpers.request!(options);
|
||||
}
|
||||
|
||||
export async function strapiApiRequestAllItems(this: IHookFunctions | ILoadOptionsFunctions | IExecuteFunctions, method: string, resource: string, body: any = {}, query: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
|
||||
export async function strapiApiRequestAllItems(this: IHookFunctions | ILoadOptionsFunctions | IExecuteFunctions, method: string, resource: string, body: any = {}, query: IDataObject = {}, headers: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
|
||||
|
||||
const returnData: IDataObject[] = [];
|
||||
|
||||
|
@ -85,7 +82,7 @@ export async function strapiApiRequestAllItems(this: IHookFunctions | ILoadOptio
|
|||
query._start = 0;
|
||||
|
||||
do {
|
||||
responseData = await strapiApiRequest.call(this, method, resource, body, query);
|
||||
responseData = await strapiApiRequest.call(this, method, resource, body, query, undefined, headers);
|
||||
query._start += query._limit;
|
||||
returnData.push.apply(returnData, responseData);
|
||||
} while (
|
||||
|
|
|
@ -66,13 +66,14 @@ export class Strapi implements INodeType {
|
|||
const returnData: IDataObject[] = [];
|
||||
const length = (items.length as unknown) as number;
|
||||
const qs: IDataObject = {};
|
||||
const headers: IDataObject = {};
|
||||
let responseData;
|
||||
const resource = this.getNodeParameter('resource', 0) as string;
|
||||
const operation = this.getNodeParameter('operation', 0) as string;
|
||||
|
||||
const { jwt } = await getToken.call(this);
|
||||
|
||||
qs.jwt = jwt;
|
||||
headers.Authorization = `Bearer ${jwt}`;
|
||||
|
||||
if (resource === 'entry') {
|
||||
if (operation === 'create') {
|
||||
|
@ -91,7 +92,7 @@ export class Strapi implements INodeType {
|
|||
body[key] = items[i].json[key];
|
||||
}
|
||||
}
|
||||
responseData = await strapiApiRequest.call(this, 'POST', `/${contentType}`, body, qs);
|
||||
responseData = await strapiApiRequest.call(this, 'POST', `/${contentType}`, body, qs, undefined, headers);
|
||||
|
||||
returnData.push(responseData);
|
||||
}
|
||||
|
@ -103,7 +104,7 @@ export class Strapi implements INodeType {
|
|||
|
||||
const entryId = this.getNodeParameter('entryId', i) as string;
|
||||
|
||||
responseData = await strapiApiRequest.call(this, 'DELETE', `/${contentType}/${entryId}`, {}, qs);
|
||||
responseData = await strapiApiRequest.call(this, 'DELETE', `/${contentType}/${entryId}`, {}, qs, undefined, headers);
|
||||
|
||||
returnData.push(responseData);
|
||||
}
|
||||
|
@ -137,11 +138,11 @@ export class Strapi implements INodeType {
|
|||
}
|
||||
|
||||
if (returnAll) {
|
||||
responseData = await strapiApiRequestAllItems.call(this, 'GET', `/${contentType}`, {}, qs);
|
||||
responseData = await strapiApiRequestAllItems.call(this, 'GET', `/${contentType}`, {}, qs, headers);
|
||||
} else {
|
||||
qs._limit = this.getNodeParameter('limit', i) as number;
|
||||
|
||||
responseData = await strapiApiRequest.call(this, 'GET', `/${contentType}`, {}, qs);
|
||||
responseData = await strapiApiRequest.call(this, 'GET', `/${contentType}`, {}, qs, undefined, headers);
|
||||
}
|
||||
returnData.push.apply(returnData, responseData);
|
||||
}
|
||||
|
@ -154,7 +155,7 @@ export class Strapi implements INodeType {
|
|||
|
||||
const entryId = this.getNodeParameter('entryId', i) as string;
|
||||
|
||||
responseData = await strapiApiRequest.call(this, 'GET', `/${contentType}/${entryId}`, {}, qs);
|
||||
responseData = await strapiApiRequest.call(this, 'GET', `/${contentType}/${entryId}`, {}, qs, undefined, headers);
|
||||
|
||||
returnData.push(responseData);
|
||||
}
|
||||
|
@ -180,7 +181,7 @@ export class Strapi implements INodeType {
|
|||
body[key] = items[i].json[key];
|
||||
}
|
||||
}
|
||||
responseData = await strapiApiRequest.call(this, 'PUT', `/${contentType}/${entryId}`, body, qs);
|
||||
responseData = await strapiApiRequest.call(this, 'PUT', `/${contentType}/${entryId}`, body, qs, undefined, headers);
|
||||
|
||||
returnData.push(responseData);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue