Monorepo containing core modules of Zeichen.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.1 KiB

  1. interface Response<T = Record<string, unknown>> {
  2. status: number,
  3. data?: T,
  4. }
  5. interface ErrorResponse extends Response {
  6. message: string,
  7. }
  8. type ResponseParams<T extends Record<string, unknown> = Record<string, unknown>> = {
  9. message?: string,
  10. data?: T,
  11. }
  12. export class NotFound implements ErrorResponse {
  13. public readonly status = 404
  14. public readonly message: string
  15. constructor(params: ResponseParams) {
  16. this.message = params.message
  17. }
  18. }
  19. export class Created<T extends Record<string, unknown>> implements Response {
  20. public readonly status = 201
  21. public readonly data: T
  22. constructor(params: ResponseParams<T>) {
  23. this.data = params.data
  24. }
  25. }
  26. export class Saved<T extends Record<string, unknown>> implements Response {
  27. public readonly status = 200
  28. public readonly data: T
  29. constructor(params: ResponseParams<T>) {
  30. this.data = params.data
  31. }
  32. }
  33. export class Retrieved<T extends Record<string, unknown>> implements Response {
  34. public readonly status = 200
  35. public readonly data: T
  36. constructor(params: ResponseParams<T>) {
  37. this.data = params.data
  38. }
  39. }