Strapi extension for Privatus
Look at this table to consider which version to use by strapi version
Strapi Verion | Library Version |
---|---|
4.15.0 | 1.0.6 |
4.16.2 | 1.1.0 |
4.20.2 | 1.2.1 |
4.24.2 | 1.2.2 |
4.25.6 | 1.2.3 |
4.25.9 | 1.2.4 |
import { EntityService } from "@strapi/strapi";
import { FindOneParameters } from "@privatus/strapi";
export type TExampleCollectionTypeContentTypeUID =
"api::example-collection-type.example-collection-type";
export const ExampleCollectionTypeContentTypeUID: TExampleCollectionTypeContentTypeUID =
"api::example-collection-type.example-collection-type";
export type ExampleCollectionTypeEntity<
TParams extends FindOneParameters<TExampleCollectionTypeContentTypeUID> = never
> = EntityService.Entity<TExampleCollectionTypeContentTypeUID, TParams>;
Collection type
import { BaseCollectionTypeService } from "@privatus/strapi";
import {
ExampleCollectionTypeEntity,
TExampleCollectionTypeContentTypeUID,
} from "../content-types/types";
import { Entity } from "@strapi/strapi";
export type ExampleCollectionTypeServiceExtension = {};
export type ExampleCollectionTypeServiceExtension = {
getById: (id: Entity.ID) => Promise<ExampleCollectionTypeEntity>;
};
export type ExampleCollectionTypeService =
BaseCollectionTypeService<TExampleCollectionTypeContentTypeUID> &
ExampleCollectionTypeServiceExtension;
Single type
import { BaseSingleTypeService } from "@privatus/strapi";
import {
ExampleSingleTypeEntity,
TExampleSingleTypeContentTypeUID,
} from "../content-types/types";
import { Entity } from "@strapi/strapi";
export type ExampleSingleTypeServiceExtension = {
getById: (id: Entity.ID) => Promise<ExampleSingleTypeEntity>;
};
export type ExampleSingleTypeService =
BaseSingleTypeService<TExampleSingleTypeContentTypeUID> &
ExampleSingleTypeServiceExtension;
import { factories } from "@strapi/strapi";
import { strapiEntityServices } from "../../../../utils/types/strapi";
import { ExampleCollectionTypeTypeUID } from "../content-types/types";
export default factories.createCoreService(
ExampleCollectionTypeTypeUID,
({ strapi }): ExampleCollectionTypeServiceExtension => ({
getById: async (id: Entity.ID) => {
return strapiEntityServices(strapi).exampleCollectionType.findOne(id);
},
})
);
import { Strapi } from "@strapi/strapi";
import { getEntityServiceAlias, strapiWrapper } from "@privatus/strapi";
import { ExampleCollectionTypeContentTypeUID } from "../../../src/api/example-collection-type/content-types/types";
import {
ExampleCollectionTypeContentTypeUID,
TExampleCollectionTypeContentTypeUID,
} from "../../../src/api/example-collection-type/content-types/types";
import { ExampleCollectionTypeService } from "../../../src/api/example-collection-type/services/types";
import {
ExampleSingleTypeContentTypeUID,
TExampleSingleTypeContentTypeUID,
} from "../../../src/api/example-single-type/content-types/types";
import { ExampleSingleTypeService } from "../../../src/api/example-single-type/services/types";
export function strapiQueries(strapi: Strapi) {
const wrapper = strapiWrapper(strapi);
return {
exampleCollectionType: wrapper.db.query(
ExampleCollectionTypeContentTypeUID
),
};
}
export function strapiEntityServices(strapi: Strapi) {
const wrapper = strapiWrapper(strapi);
return {
exampleCollectionType: getEntityServiceAlias(
wrapper,
ExampleCollectionTypeContentTypeUID
),
exampleSingleType: getEntityServiceAlias(
wrapper,
ExampleSingleTypeContentTypeUID
),
plugin: {},
};
}
export function strapiServices(strapi: Strapi) {
const wrapper = strapiWrapper(strapi);
return {
exampleCollectionType: wrapper.service<
TExampleCollectionTypeContentTypeUID,
ExampleCollectionTypeService
>(ExampleCollectionTypeContentTypeUID),
exampleSingleType: wrapper.service<
TExampleSingleTypeContentTypeUID,
ExampleSingleTypeService
>(ExampleSingleTypeContentTypeUID),
plugin: {
userPermissions: {
jwt: wrapper.service("plugin::users-permissions.jwt"),
},
},
};
}
const entity = await strapiServices(strapi).exampleCollectionType.getById(1);