diff --git a/src/client.ts b/src/client.ts index a41f914..50f2cab 100644 --- a/src/client.ts +++ b/src/client.ts @@ -4,6 +4,14 @@ import type { TransportConnection, Application } from '@feathersjs/feathers' import authenticationClient from '@feathersjs/authentication-client' import type { AuthenticationClientOptions } from '@feathersjs/authentication-client' +import { tfAgegroupClient } from './services/track-field/agegroup/agegroup.shared' +export type { + TfAgegroup, + TfAgegroupData, + TfAgegroupQuery, + TfAgegroupPatch +} from './services/track-field/agegroup/agegroup.shared' + import { tfItemClient } from './services/track-field/item/item.shared' export type { TfItem, TfItemData, TfItemQuery, TfItemPatch } from './services/track-field/item/item.shared' @@ -56,5 +64,6 @@ export const createClient = ( client.configure(tfSeasonClient) client.configure(tfTeamClient) client.configure(tfItemClient) + client.configure(tfAgegroupClient) return client } diff --git a/src/services/index.ts b/src/services/index.ts index 840d556..55785fc 100644 --- a/src/services/index.ts +++ b/src/services/index.ts @@ -1,3 +1,4 @@ +import { tfAgegroup } from './track-field/agegroup/agegroup' import { tfItem } from './track-field/item/item' import { tfPlayer } from './track-field/player/player' import { tfTeam } from './track-field/team/team' @@ -6,6 +7,7 @@ import { tfSeason } from './track-field/season/season' import type { Application } from '../declarations' export const services = (app: Application) => { + app.configure(tfAgegroup) app.configure(tfItem) app.configure(tfPlayer) app.configure(tfTeam) diff --git a/src/services/track-field/agegroup/agegroup.class.ts b/src/services/track-field/agegroup/agegroup.class.ts new file mode 100644 index 0000000..7eee27f --- /dev/null +++ b/src/services/track-field/agegroup/agegroup.class.ts @@ -0,0 +1,27 @@ +// For more information about this file see https://dove.feathersjs.com/guides/cli/service.class.html#database-services +import type { Params } from '@feathersjs/feathers' +import { KnexService } from '@feathersjs/knex' +import type { KnexAdapterParams, KnexAdapterOptions } from '@feathersjs/knex' + +import type { Application } from '../../../declarations' +import type { TfAgegroup, TfAgegroupData, TfAgegroupPatch, TfAgegroupQuery } from './agegroup.schema' + +export type { TfAgegroup, TfAgegroupData, TfAgegroupPatch, TfAgegroupQuery } + +export interface TfAgegroupParams extends KnexAdapterParams {} + +// By default calls the standard Knex adapter service methods but can be customized with your own functionality. +export class TfAgegroupService extends KnexService< + TfAgegroup, + TfAgegroupData, + TfAgegroupParams, + TfAgegroupPatch +> {} + +export const getOptions = (app: Application): KnexAdapterOptions => { + return { + paginate: app.get('paginate'), + Model: app.get('mysqlClient'), + name: 'ctfc_agegroup' + } +} diff --git a/src/services/track-field/agegroup/agegroup.schema.ts b/src/services/track-field/agegroup/agegroup.schema.ts new file mode 100644 index 0000000..400e150 --- /dev/null +++ b/src/services/track-field/agegroup/agegroup.schema.ts @@ -0,0 +1,58 @@ +// // For more information about this file see https://dove.feathersjs.com/guides/cli/service.schemas.html +import { resolve } from '@feathersjs/schema' +import { Type, getValidator, querySyntax } from '@feathersjs/typebox' +import type { Static } from '@feathersjs/typebox' + +import type { HookContext } from '../../../declarations' +import { dataValidator, queryValidator } from '../../../validators' +import { toLowerCaseProperty } from '../../../utilities/property-name-converter' + +// Main data model schema +export const tfAgegroupSchema = Type.Object( + { + id: Type.Number(), + name: Type.String(), + minage: Type.Number(), + maxage: Type.Number() + }, + { $id: 'TfAgegroup', additionalProperties: false } +) +export type TfAgegroup = Static +export const tfAgegroupValidator = getValidator(tfAgegroupSchema, dataValidator) +export const tfAgegroupResolver = resolve({}, { + converter: async (rawData) => { + return toLowerCaseProperty(rawData, tfAgegroupSchema) + } +}); + +export const tfAgegroupExternalResolver = resolve({}) + +// Schema for creating new entries +export const tfAgegroupDataSchema = Type.Pick(tfAgegroupSchema, ['name'], { + $id: 'TfAgegroupData' +}) +export type TfAgegroupData = Static +export const tfAgegroupDataValidator = getValidator(tfAgegroupDataSchema, dataValidator) +export const tfAgegroupDataResolver = resolve({}) + +// Schema for updating existing entries +export const tfAgegroupPatchSchema = Type.Partial(tfAgegroupSchema, { + $id: 'TfAgegroupPatch' +}) +export type TfAgegroupPatch = Static +export const tfAgegroupPatchValidator = getValidator(tfAgegroupPatchSchema, dataValidator) +export const tfAgegroupPatchResolver = resolve({}) + +// Schema for allowed query properties +export const tfAgegroupQueryProperties = Type.Pick(tfAgegroupSchema, ['id', 'name','minage','maxage']) +export const tfAgegroupQuerySchema = Type.Intersect( + [ + querySyntax(tfAgegroupQueryProperties), + // Add additional query properties here + Type.Object({}, { additionalProperties: false }) + ], + { additionalProperties: false } +) +export type TfAgegroupQuery = Static +export const tfAgegroupQueryValidator = getValidator(tfAgegroupQuerySchema, queryValidator) +export const tfAgegroupQueryResolver = resolve({}) diff --git a/src/services/track-field/agegroup/agegroup.shared.ts b/src/services/track-field/agegroup/agegroup.shared.ts new file mode 100644 index 0000000..5225a74 --- /dev/null +++ b/src/services/track-field/agegroup/agegroup.shared.ts @@ -0,0 +1,36 @@ +// For more information about this file see https://dove.feathersjs.com/guides/cli/service.shared.html +import type { Params } from '@feathersjs/feathers' +import type { ClientApplication } from '../../../client' +import type { + TfAgegroup, + TfAgegroupData, + TfAgegroupPatch, + TfAgegroupQuery, + TfAgegroupService +} from './agegroup.class' + +export type { TfAgegroup, TfAgegroupData, TfAgegroupPatch, TfAgegroupQuery } + +export type TfAgegroupClientService = Pick< + TfAgegroupService>, + (typeof tfAgegroupMethods)[number] +> + +export const tfAgegroupPath = 'track-field/agegroup' + +export const tfAgegroupMethods = ['find', 'get', 'create', 'patch', 'remove'] as const + +export const tfAgegroupClient = (client: ClientApplication) => { + const connection = client.get('connection') + + client.use(tfAgegroupPath, connection.service(tfAgegroupPath), { + methods: tfAgegroupMethods + }) +} + +// Add this service to the client service type index +declare module '../../../client' { + interface ServiceTypes { + [tfAgegroupPath]: TfAgegroupClientService + } +} diff --git a/src/services/track-field/agegroup/agegroup.ts b/src/services/track-field/agegroup/agegroup.ts new file mode 100644 index 0000000..26c8692 --- /dev/null +++ b/src/services/track-field/agegroup/agegroup.ts @@ -0,0 +1,71 @@ +// For more information about this file see https://dove.feathersjs.com/guides/cli/service.html + +import { hooks as schemaHooks } from '@feathersjs/schema' + +import { + tfAgegroupDataValidator, + tfAgegroupPatchValidator, + tfAgegroupQueryValidator, + tfAgegroupResolver, + tfAgegroupExternalResolver, + tfAgegroupDataResolver, + tfAgegroupPatchResolver, + tfAgegroupQueryResolver +} from './agegroup.schema' + +import type { Application } from '../../../declarations' +import { TfAgegroupService, getOptions } from './agegroup.class' +import { tfAgegroupPath, tfAgegroupMethods } from './agegroup.shared' + +export * from './agegroup.class' +export * from './agegroup.schema' + +// A configure function that registers the service and its hooks via `app.configure` +export const tfAgegroup = (app: Application) => { + // Register our service on the Feathers application + app.use(tfAgegroupPath, new TfAgegroupService(getOptions(app)), { + // A list of all methods this service exposes externally + methods: tfAgegroupMethods, + // You can add additional custom events to be sent to clients here + events: [] + }) + // Initialize hooks + app.service(tfAgegroupPath).hooks({ + around: { + all: [ + schemaHooks.resolveExternal(tfAgegroupExternalResolver), + schemaHooks.resolveResult(tfAgegroupResolver) + ] + }, + before: { + all: [ + schemaHooks.validateQuery(tfAgegroupQueryValidator), + schemaHooks.resolveQuery(tfAgegroupQueryResolver) + ], + find: [], + get: [], + create: [ + schemaHooks.validateData(tfAgegroupDataValidator), + schemaHooks.resolveData(tfAgegroupDataResolver) + ], + patch: [ + schemaHooks.validateData(tfAgegroupPatchValidator), + schemaHooks.resolveData(tfAgegroupPatchResolver) + ], + remove: [] + }, + after: { + all: [] + }, + error: { + all: [] + } + }) +} + +// Add this service to the service type index +declare module '../../../declarations' { + interface ServiceTypes { + [tfAgegroupPath]: TfAgegroupService + } +} diff --git a/test/services/track-field/agegroup/agegroup.test.ts b/test/services/track-field/agegroup/agegroup.test.ts new file mode 100644 index 0000000..0598f1e --- /dev/null +++ b/test/services/track-field/agegroup/agegroup.test.ts @@ -0,0 +1,11 @@ +// For more information about this file see https://dove.feathersjs.com/guides/cli/service.test.html +import assert from 'assert' +import { app } from '../../../../src/app' + +describe('track-field/agegroup service', () => { + it('registered the service', () => { + const service = app.service('track-field/agegroup') + + assert.ok(service, 'Registered the service') + }) +})