add user service

This commit is contained in:
AntoXa PRO 2024-06-06 12:55:01 +03:00
parent 540c165e94
commit 5e772c525a
2 changed files with 18 additions and 10 deletions

View File

@ -1,8 +1,7 @@
{ {
"name": "directus-helpers", "name": "directus-helpers",
"version": "1.1.0", "version": "1.2.0",
"description": "Helpers Directus Extensions", "description": "Helpers Directus Extensions",
"license": "ISC",
"author": "AntoXa PRO <info@antoxa.pro>", "author": "AntoXa PRO <info@antoxa.pro>",
"homepage": "https://antoxahub.ru/antoxa/directus-helpers", "homepage": "https://antoxahub.ru/antoxa/directus-helpers",
"repository": { "repository": {
@ -30,9 +29,6 @@
"build": "vite build", "build": "vite build",
"prepare": "npm run build" "prepare": "npm run build"
}, },
"keywords": [
"Directus"
],
"devDependencies": { "devDependencies": {
"@directus/api": "latest", "@directus/api": "latest",
"@directus/extensions-sdk": "latest", "@directus/extensions-sdk": "latest",

View File

@ -1,5 +1,9 @@
import type { SchemaOverview, Accountability } from '@directus/types' 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 = { export type TFactoryServicesOpts = {
services: any services: any
@ -10,13 +14,12 @@ export type TFactoryServicesOpts = {
type TServices<K extends keyof any> = { [P in K]: any } type TServices<K extends keyof any> = { [P in K]: any }
export type TFactoryTypes = Record<string, any> export type TFactoryTypes = Record<string, any>
export class FactoryServices< export class FactoryServices<TTypes extends TFactoryTypes = any> {
TTypes extends TFactoryTypes = any,
> {
private opts: TFactoryServicesOpts private opts: TFactoryServicesOpts
private _items: Partial<TServices<keyof TTypes>> = {} private _items: Partial<TServices<keyof TTypes>> = {}
private _files: FilesService | null = null private _files: FilesService | null = null
private _users: UsersService | null = null
constructor(opts: TFactoryServicesOpts) { constructor(opts: TFactoryServicesOpts) {
this.opts = opts this.opts = opts
@ -43,5 +46,14 @@ export class FactoryServices<
} }
return this._files as FilesService 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
}
}