Skip to content

Custom service method causing typebox issue #3092

Answered by daffl
laurensiusadi asked this question in Q&A
Discussion options

You must be logged in to vote

The method should return something. This will probably work:

export class ProductService<ServiceParams extends Params = ProductParams> extends KnexService<
  Product,
  ProductData,
  ProductParams,
  ProductPatch
> {
  async save(data: Product) {
    try {
      const [record] = await this.find({ query: { id: data.id }, paginate: false })
      if (record) {
        return this.patch(data.id, data)
      } else {
        return this.create(data)
      }
    } catch (error: any) {
      console.log('Error saving product: ', error)
    }
  }
}

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@laurensiusadi
Comment options

Answer selected by laurensiusadi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants