// app/exampleComponent/controllers/trpc/ExampleProcedures/index.ts
import {Procedures, TQuery, TMutation, createTQuery, createTMutation} from '@orion-js/trpc'
import {Inject} from '@orion-js/services'
import {ExampleSchema} from 'app/exampleComponent/schemas/ExampleSchema'
import {ExampleService} from 'app/exampleComponent/services/ExampleService'
@Procedures()
export class ExampleProcedures {
@Inject(() => ExampleService)
private exampleService: ExampleService
@TQuery()
getExample = createTQuery({
params: {exampleId: {type: String}},
returns: ExampleSchema,
resolve: async ({exampleId}) => {
return await this.exampleService.getExample(exampleId)
},
})
@TQuery()
listExamples = createTQuery({
returns: [ExampleSchema],
resolve: async () => {
return await this.exampleService.getExamples()
},
})
@TMutation()
createExample = createTMutation({
params: {name: {type: String}},
returns: {message: {type: String}},
resolve: async ({name}) => {
await this.exampleService.createExample(name)
return {message: 'Created successfully'}
},
})
}