ekyc

Electronic KYC process with uploading ID document using OAuth 2.1 (experimental)
Log | Files | Refs | README | LICENSE

id-document.tsx (2035B)


      1 import { AppState } from "#http/routes/_middleware.ts";
      2 import { IDDocumentDto } from "#infrastructure/memory/mapper/id_document.ts";
      3 import { PageProps } from "$fresh/server.ts";
      4 import { Handlers } from "$fresh/src/server/types.ts";
      5 import * as V from "$valita";
      6 
      7 type Props = {
      8   items: IDDocumentDto[];
      9   next: URL;
     10 };
     11 
     12 export const handler: Handlers<Props, AppState<"/verify/id-document">> = {
     13   async GET(_req, ctx) {
     14     const { app, forms, formContext } = ctx.state;
     15     const { idDocumentList } = app;
     16     if (formContext === null) {
     17       return forms.redirect({
     18         form: "/verify/id-document",
     19         context: { cursor: 0 },
     20       });
     21     }
     22     const { cursor } = formContext;
     23     if (forms.session === null) {
     24       return forms.redirect({
     25         form: "/verify/id-document",
     26         context: formContext,
     27       });
     28     }
     29     const { items, next: nextCursor } = await idDocumentList.execute({
     30       cursor,
     31     });
     32     const next = forms.link({
     33       form: "/verify/id-document",
     34       context: { cursor: nextCursor },
     35     });
     36     return ctx.render({ items, next });
     37   },
     38 
     39   async POST(req, ctx) {
     40     const { app, forms, formContext } = ctx.state;
     41     const { idDocumentApprove, idDocumentDecline } = app;
     42     if (formContext === null) {
     43       return forms.redirect("/");
     44     }
     45     if (forms.session === null) {
     46       return forms.redirect({
     47         form: "/verify/id-document",
     48         context: formContext,
     49       });
     50     }
     51 
     52     const { uuid, approved } = await forms.inputs(
     53       req,
     54       V.object({
     55         uuid: V.string(),
     56         approved: V.string().map(() => true).default(false),
     57       }),
     58     );
     59 
     60     if (approved) {
     61       await idDocumentApprove.execute({
     62         admin: forms.session.uuid,
     63         uuid,
     64       });
     65     } else {
     66       await idDocumentDecline.execute({
     67         admin: forms.session.uuid,
     68         uuid,
     69       });
     70     }
     71 
     72     return await this.GET!(req, ctx);
     73   },
     74 };
     75 
     76 export default function IDDocumentPage(
     77   props: PageProps<Props, AppState<"/verify/id-document">>,
     78 ) {
     79   return null
     80 }