From 5e772c525a17258f470d19559166916630b6874f Mon Sep 17 00:00:00 2001 From: AntoXa PRO Date: Thu, 6 Jun 2024 12:55:01 +0300 Subject: [PATCH] add user service --- package.json | 6 +----- src/services/factory.ts | 22 +++++++++++++++++----- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index 390c966..d8b727e 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,7 @@ { "name": "directus-helpers", - "version": "1.1.0", + "version": "1.2.0", "description": "Helpers Directus Extensions", - "license": "ISC", "author": "AntoXa PRO ", "homepage": "https://antoxahub.ru/antoxa/directus-helpers", "repository": { @@ -30,9 +29,6 @@ "build": "vite build", "prepare": "npm run build" }, - "keywords": [ - "Directus" - ], "devDependencies": { "@directus/api": "latest", "@directus/extensions-sdk": "latest", diff --git a/src/services/factory.ts b/src/services/factory.ts index 910e20b..6d699a0 100644 --- a/src/services/factory.ts +++ b/src/services/factory.ts @@ -1,5 +1,9 @@ import type { SchemaOverview, Accountability } from '@directus/types' -import type { ItemsService, FilesService } from '@directus/api/dist/services' +import type { + ItemsService, + FilesService, + UsersService +} from '@directus/api/dist/services' export type TFactoryServicesOpts = { services: any @@ -10,13 +14,12 @@ export type TFactoryServicesOpts = { type TServices = { [P in K]: any } export type TFactoryTypes = Record -export class FactoryServices< - TTypes extends TFactoryTypes = any, -> { +export class FactoryServices { private opts: TFactoryServicesOpts private _items: Partial> = {} private _files: FilesService | null = null + private _users: UsersService | null = null constructor(opts: TFactoryServicesOpts) { this.opts = opts @@ -43,5 +46,14 @@ export class FactoryServices< } return this._files as FilesService } -} + users() { + if (!this._users) { + this._users = new this.opts.services.UserService({ + schema: this.opts.schema, + accountability: this.opts.accountability + }) + } + return this._users as UsersService + } +}