Zeichen's app for both server and client.
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.

Response.ts 1.0 KiB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. interface Response<T extends {} = {}> {
  2. status: number,
  3. data?: T,
  4. }
  5. interface ErrorResponse extends Response {
  6. message: string,
  7. }
  8. type ResponseParams<T extends {} = {}> = {
  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 {}> 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 {}> 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 {}> implements Response {
  34. public readonly status = 200
  35. public readonly data: T
  36. constructor(params: ResponseParams<T>) {
  37. this.data = params.data
  38. }
  39. }
  40. export class Destroyed implements Response {
  41. public readonly status = 204
  42. }