mirror of
https://github.com/strapi/strapi.git
synced 2025-12-06 03:52:38 +00:00
Merge pull request #20004 from strapi/fix/doc-service-middleware-type
fix: middleware type
This commit is contained in:
commit
266491e4b8
@ -124,7 +124,7 @@ describe('history-version service', () => {
|
|||||||
|
|
||||||
// Check that we don't break the middleware chain
|
// Check that we don't break the middleware chain
|
||||||
await historyMiddlewareFunction(context, next);
|
await historyMiddlewareFunction(context, next);
|
||||||
expect(next).toHaveBeenCalledWith(context);
|
expect(next).toHaveBeenCalled();
|
||||||
|
|
||||||
// Create and update actions should be saved in history
|
// Create and update actions should be saved in history
|
||||||
expect(createMock).toHaveBeenCalled();
|
expect(createMock).toHaveBeenCalled();
|
||||||
@ -157,7 +157,7 @@ describe('history-version service', () => {
|
|||||||
// Don't break middleware chain even if we don't save the action in history
|
// Don't break middleware chain even if we don't save the action in history
|
||||||
next.mockClear();
|
next.mockClear();
|
||||||
await historyMiddlewareFunction(context, next);
|
await historyMiddlewareFunction(context, next);
|
||||||
expect(next).toHaveBeenCalledWith(context);
|
expect(next).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should create a cron job that runs once a day', async () => {
|
it('should create a cron job that runs once a day', async () => {
|
||||||
|
|||||||
@ -72,24 +72,24 @@ const createHistoryService = ({ strapi }: { strapi: Core.LoadedStrapi }) => {
|
|||||||
strapi.documents.use(async (context, next) => {
|
strapi.documents.use(async (context, next) => {
|
||||||
// Ignore requests that are not related to the content manager
|
// Ignore requests that are not related to the content manager
|
||||||
if (!strapi.requestContext.get()?.request.url.startsWith('/content-manager')) {
|
if (!strapi.requestContext.get()?.request.url.startsWith('/content-manager')) {
|
||||||
return next(context);
|
return next();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ignore actions that don't mutate documents
|
// Ignore actions that don't mutate documents
|
||||||
if (
|
if (
|
||||||
!['create', 'update', 'publish', 'unpublish', 'discardDraft'].includes(context.action)
|
!['create', 'update', 'publish', 'unpublish', 'discardDraft'].includes(context.action)
|
||||||
) {
|
) {
|
||||||
return next(context);
|
return next();
|
||||||
}
|
}
|
||||||
|
|
||||||
// @ts-expect-error ContentType is not typed correctly on the context
|
// @ts-expect-error ContentType is not typed correctly on the context
|
||||||
const contentTypeUid = context.contentType.uid;
|
const contentTypeUid = context.contentType.uid;
|
||||||
// Ignore content types not created by the user
|
// Ignore content types not created by the user
|
||||||
if (!contentTypeUid.startsWith('api::')) {
|
if (!contentTypeUid.startsWith('api::')) {
|
||||||
return next(context);
|
return next();
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = (await next(context)) as any;
|
const result = (await next()) as any;
|
||||||
|
|
||||||
const documentContext =
|
const documentContext =
|
||||||
context.action === 'create'
|
context.action === 'create'
|
||||||
|
|||||||
@ -13,5 +13,5 @@ export interface Context<
|
|||||||
|
|
||||||
export type Middleware = (
|
export type Middleware = (
|
||||||
ctx: Context,
|
ctx: Context,
|
||||||
next: (ctx: Context) => ReturnType<ServiceInstance[keyof ServiceInstance]>
|
next: () => ReturnType<ServiceInstance[keyof ServiceInstance]>
|
||||||
) => ReturnType<ServiceInstance[keyof ServiceInstance]>;
|
) => ReturnType<ServiceInstance[keyof ServiceInstance]>;
|
||||||
|
|||||||
@ -19,11 +19,11 @@ const registerModelsHooks = () => {
|
|||||||
const schema: Schema.ContentType = context.contentType;
|
const schema: Schema.ContentType = context.contentType;
|
||||||
|
|
||||||
if (!['create', 'update', 'discardDraft', 'publish'].includes(context.action)) {
|
if (!['create', 'update', 'discardDraft', 'publish'].includes(context.action)) {
|
||||||
return next(context);
|
return next();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!getService('content-types').isLocalizedContentType(schema)) {
|
if (!getService('content-types').isLocalizedContentType(schema)) {
|
||||||
return next(context);
|
return next();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build a populate array for all non localized fields within the schema
|
// Build a populate array for all non localized fields within the schema
|
||||||
@ -32,7 +32,7 @@ const registerModelsHooks = () => {
|
|||||||
const attributesToPopulate = getNestedPopulateOfNonLocalizedAttributes(schema.uid);
|
const attributesToPopulate = getNestedPopulateOfNonLocalizedAttributes(schema.uid);
|
||||||
|
|
||||||
// Get the result of the document service action
|
// Get the result of the document service action
|
||||||
const result = (await next(context)) as any;
|
const result = (await next()) as any;
|
||||||
|
|
||||||
// We may not have received a result with everything populated that we need
|
// We may not have received a result with everything populated that we need
|
||||||
// Use the id and populate built from non localized fields to get the full
|
// Use the id and populate built from non localized fields to get the full
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user