common.ts 975 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. export class ResultDto<T = any> {
  3. ok: boolean;
  4. status: number;
  5. message?: string|null;
  6. data: T|null;
  7. errors?: Record<string, string[]>|null;
  8. constructor({
  9. ok = false,
  10. status = 500,
  11. message = null,
  12. data = null,
  13. errors = null
  14. }: Partial<ResultDto<T>>) {
  15. this.ok = ok;
  16. this.status = status;
  17. this.message = message;
  18. this.data = data;
  19. this.errors = errors;
  20. }
  21. public getError(index: number = 0): string|undefined {
  22. if (this.errors) {
  23. const errorKeys = Object.keys(this.errors);
  24. if (errorKeys.length > 0) {
  25. const key = errorKeys[index];
  26. if (key) {
  27. return this.errors[key][0];
  28. }
  29. }
  30. }
  31. return undefined;
  32. }
  33. };
  34. */
  35. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  36. export interface ResultDto<T = any> {
  37. ok: boolean;
  38. status: number;
  39. message: string|null;
  40. data: T|null;
  41. errors: Record<string, string[]>|null;
  42. }
  43. export interface TokenData {
  44. id: string;
  45. email: string;
  46. name: string|null;
  47. }