iddocument_list.ts (1351B)
1 import { 2 IDDocumentListRequest, 3 IDDocumentListResponse, 4 IDDocumentListUseCase, 5 } from "#core/application/id_document/list.ts"; 6 import { Pool } from "$postgres"; 7 8 const NB_PER_PAGE = 10; 9 10 export class PostgresIDDocumentListAdapter implements IDDocumentListUseCase { 11 constructor(private readonly pool: Pool) { 12 } 13 14 async execute( 15 request: IDDocumentListRequest, 16 ): Promise<IDDocumentListResponse> { 17 const connection = await this.pool.connect(); 18 try { 19 const items = await connection.queryObject< 20 IDDocumentListResponse["items"][number] 21 >` 22 select "uuid", 23 "front" as "docFront", 24 "back" as "docBack", 25 "faceLeft", 26 "faceFront", 27 "faceRight", 28 "firstName", 29 "lastName", 30 "birthDate", 31 "sex", 32 "nationality", 33 "country" 34 from "id_document" 35 where "state" = 'registered' 36 limit ${NB_PER_PAGE} offset ${request.cursor ?? 0} 37 `; 38 return { 39 items: items.rows, 40 next: (request.cursor ?? 0) + NB_PER_PAGE, 41 }; 42 } finally { 43 connection.release(); 44 } 45 } 46 }