index.ts118 lines, 2.1 KB
| 1 | // shared typescript types defenitions for all microservices |
| 2 | |
| 3 | export interface User { |
| 4 | id: string; |
| 5 | email: string; |
| 6 | createdAt: Date; |
| 7 | updatedAt: Date; |
| 8 | } |
| 9 | |
| 10 | export interface UserProfile { |
| 11 | id: string; |
| 12 | userId: string; |
| 13 | firstName?: string | null; |
| 14 | lastName?: string | null; |
| 15 | bio?: string | null; |
| 16 | avatarUrl?: string | null; |
| 17 | preferences?: any; |
| 18 | createdAt: Date; |
| 19 | updatedAt: Date; |
| 20 | } |
| 21 | |
| 22 | export interface UpdateProfileRequest { |
| 23 | firstName?: string | null; |
| 24 | lastName?: string | null; |
| 25 | bio?: string | null; |
| 26 | avatarUrl?: string | null; |
| 27 | preferences?: Record<string, any>; |
| 28 | } |
| 29 | |
| 30 | export interface Note { |
| 31 | id: string; |
| 32 | title: string; |
| 33 | content: string; |
| 34 | isDeleted: boolean; |
| 35 | createdAt: Date; |
| 36 | updatedAt: Date; |
| 37 | tags?: Tag[]; |
| 38 | } |
| 39 | |
| 40 | export interface Tag { |
| 41 | id: string; |
| 42 | name: string; |
| 43 | color?: string; |
| 44 | userId: string; |
| 45 | updatedAt: Date; |
| 46 | } |
| 47 | |
| 48 | export interface CreateTagRequest { |
| 49 | name: string; |
| 50 | color?: string; |
| 51 | } |
| 52 | |
| 53 | export interface CreateNoteRequest { |
| 54 | title: string; |
| 55 | content: string; |
| 56 | tagIds?: string[]; |
| 57 | } |
| 58 | |
| 59 | export interface UpdateNoteRequest { |
| 60 | title?: string; |
| 61 | content?: string; |
| 62 | tagIds?: string[]; |
| 63 | } |
| 64 | |
| 65 | export interface ServiceResponse<T = any> { |
| 66 | success: boolean; |
| 67 | data?: T; |
| 68 | error?: string; |
| 69 | statusCode?: number; |
| 70 | } |
| 71 | |
| 72 | export interface ApiResponse<T = any> { |
| 73 | success: boolean; |
| 74 | data?: T; |
| 75 | message?: string; |
| 76 | error?: string; |
| 77 | errors?: Record<string, string[]>; |
| 78 | } |
| 79 | |
| 80 | export interface AuthTokens { |
| 81 | accessToken: string; |
| 82 | refreshToken: string; |
| 83 | } |
| 84 | |
| 85 | export interface JWTPayload { |
| 86 | userId: string; |
| 87 | email: string; |
| 88 | iat: number; // issued at |
| 89 | exp: number; // expiration time |
| 90 | } |
| 91 | |
| 92 | export class ServiceError extends Error { |
| 93 | statusCode: number; |
| 94 | code?: string; |
| 95 | details?: any; |
| 96 | |
| 97 | constructor( |
| 98 | message: string, |
| 99 | statusCode: number = 500, |
| 100 | code?: string, |
| 101 | details?: any |
| 102 | ) { |
| 103 | super(message); |
| 104 | this.name = "ServiceError"; |
| 105 | this.statusCode = statusCode; |
| 106 | this.code = code; |
| 107 | this.details = details; |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | export function logError(error: Error, context?: Record<string, any>): void { |
| 112 | console.error("Error occurred", { |
| 113 | message: error.message, |
| 114 | stack: error.stack, |
| 115 | context, |
| 116 | timestamp: new Date().toISOString(), |
| 117 | }); |
| 118 | } |