From b41b7426a598c5903aba4f5269ebb8dd9df37817 Mon Sep 17 00:00:00 2001 From: Jeroen Branje Date: Thu, 25 Jan 2024 14:15:49 +0100 Subject: [PATCH] refactor: api to server components Signed-off-by: Jeroen Branje --- apps/envited.ascs.digital/app/api/utils.ts | 1 - .../app/dashboard/users/page.tsx | 1 + apps/envited.ascs.digital/common/i18n/useI18n.ts | 6 +++++- .../common/server/users/getUserById.ts | 2 +- .../common/server/users/getUsersByIssuerId.test.ts | 6 ++++-- apps/envited.ascs.digital/common/server/utils.ts | 1 - .../modules/Users/Users.test.tsx | 12 +++++++----- apps/envited.ascs.digital/modules/Users/Users.tsx | 6 +++--- 8 files changed, 21 insertions(+), 14 deletions(-) diff --git a/apps/envited.ascs.digital/app/api/utils.ts b/apps/envited.ascs.digital/app/api/utils.ts index eb1676c7..d138354c 100644 --- a/apps/envited.ascs.digital/app/api/utils.ts +++ b/apps/envited.ascs.digital/app/api/utils.ts @@ -2,7 +2,6 @@ import { equals, pathOr, prop } from 'ramda' import { Role, Session, User } from '../../common/types/types' - export const extractIdFromCredential = pathOr('', ['credentialSubject', 'id']) export const extractIssuerIdFromCredential = pathOr('', ['issuer', 'id']) diff --git a/apps/envited.ascs.digital/app/dashboard/users/page.tsx b/apps/envited.ascs.digital/app/dashboard/users/page.tsx index bef722f5..1a75b0cd 100644 --- a/apps/envited.ascs.digital/app/dashboard/users/page.tsx +++ b/apps/envited.ascs.digital/app/dashboard/users/page.tsx @@ -1,4 +1,5 @@ import { getUsersByIssuerId } from 'apps/envited.ascs.digital/common/server' + import { Users } from '../../../modules/Users' export default async function Index() { diff --git a/apps/envited.ascs.digital/common/i18n/useI18n.ts b/apps/envited.ascs.digital/common/i18n/useI18n.ts index d1acddf3..4a9b2323 100644 --- a/apps/envited.ascs.digital/common/i18n/useI18n.ts +++ b/apps/envited.ascs.digital/common/i18n/useI18n.ts @@ -8,7 +8,11 @@ import { Locale, TranslationsMap } from './types' const getTranslationsForLanguage = (namespace: string) => (locale: Locale) => pathOr({}, [locale, namespace]) const mergeTranslations = reduce(mergeDeepRight, { [Locale.en_GB]: {}, [Locale.de_DE]: {} }) -const translationObject = mergeTranslations([HeaderTranslation, HeroHeaderTranslation, UsersTranslation]) as TranslationsMap +const translationObject = mergeTranslations([ + HeaderTranslation, + HeroHeaderTranslation, + UsersTranslation, +]) as TranslationsMap export const translation = (translations: TranslationsMap) => (namespace: string) => { const t = (key: string): React.ReactElement => diff --git a/apps/envited.ascs.digital/common/server/users/getUserById.ts b/apps/envited.ascs.digital/common/server/users/getUserById.ts index b6d9c1f5..26e8d241 100644 --- a/apps/envited.ascs.digital/common/server/users/getUserById.ts +++ b/apps/envited.ascs.digital/common/server/users/getUserById.ts @@ -1,13 +1,13 @@ import { isNil } from 'ramda' import { cache } from 'react' -import { isOwnUser, userIsIssuedByLoggedInUser } from '../utils' import { getServerSession } from '../../auth' import { db } from '../../database/queries' import { Database } from '../../database/types' import { User } from '../../types' import { Session } from '../../types/types' import { badRequestError, error, unauthorizedError } from '../../utils' +import { isOwnUser, userIsIssuedByLoggedInUser } from '../utils' export const _getUserById = ({ db, getServerSession }: { db: Database; getServerSession: () => Promise }) => diff --git a/apps/envited.ascs.digital/common/server/users/getUsersByIssuerId.test.ts b/apps/envited.ascs.digital/common/server/users/getUsersByIssuerId.test.ts index 6fcf450b..f1056b34 100644 --- a/apps/envited.ascs.digital/common/server/users/getUsersByIssuerId.test.ts +++ b/apps/envited.ascs.digital/common/server/users/getUsersByIssuerId.test.ts @@ -10,7 +10,7 @@ describe('common/server/users/getUsersByIssuerId', () => { Promise.resolve({ user: { pkh: 'USER_ISSUER_ID', - role: Role.federator + role: Role.federator, }, }), ) @@ -32,7 +32,9 @@ describe('common/server/users/getUsersByIssuerId', () => { }), ) - const result = await SUT._getUsersByIssuerId({ db: dbStub, getServerSession: getServerSessionStub })('USER_ISSUER_ID') + const result = await SUT._getUsersByIssuerId({ db: dbStub, getServerSession: getServerSessionStub })( + 'USER_ISSUER_ID', + ) expect(result).toEqual([user]) }) diff --git a/apps/envited.ascs.digital/common/server/utils.ts b/apps/envited.ascs.digital/common/server/utils.ts index 32b9f85f..1bd181ba 100644 --- a/apps/envited.ascs.digital/common/server/utils.ts +++ b/apps/envited.ascs.digital/common/server/utils.ts @@ -2,7 +2,6 @@ import { equals, pathOr, prop } from 'ramda' import { Role, Session, User } from '../../common/types/types' - export const extractIdFromCredential = pathOr('', ['credentialSubject', 'id']) export const extractIssuerIdFromCredential = pathOr('', ['issuer', 'id']) diff --git a/apps/envited.ascs.digital/modules/Users/Users.test.tsx b/apps/envited.ascs.digital/modules/Users/Users.test.tsx index d69dce03..97166aea 100644 --- a/apps/envited.ascs.digital/modules/Users/Users.test.tsx +++ b/apps/envited.ascs.digital/modules/Users/Users.test.tsx @@ -4,11 +4,13 @@ import { Users } from './Users' describe('Users', () => { it('should render successfully', () => { - const USERS_MAP = [{ - name: 'John Johnson', - email: 'j.johnson@ascs.digital', - id: 'did:pkh:tz:tz1SfdVU1mor3Sgej3FmmwMH4HM1EjTzqqeE', - }] + const USERS_MAP = [ + { + name: 'John Johnson', + email: 'j.johnson@ascs.digital', + id: 'did:pkh:tz:tz1SfdVU1mor3Sgej3FmmwMH4HM1EjTzqqeE', + }, + ] const { baseElement } = render() expect(baseElement).toBeTruthy() diff --git a/apps/envited.ascs.digital/modules/Users/Users.tsx b/apps/envited.ascs.digital/modules/Users/Users.tsx index 05142972..1575d7b3 100644 --- a/apps/envited.ascs.digital/modules/Users/Users.tsx +++ b/apps/envited.ascs.digital/modules/Users/Users.tsx @@ -1,11 +1,11 @@ 'use client' import { Card, Heading, Table, TableBody, TableCell, TableHeader, TableRow } from '@envited-marketplace/design-system' +import { map } from 'ramda' import React, { FC } from 'react' import { useTranslation } from '../../common/i18n' import { User } from '../../common/types/types' -import { map } from 'ramda' interface UsersProps { users: Partial[] @@ -31,13 +31,13 @@ export const Users: FC = ({ users }) => { - {map(({id, name, email }: Partial) => + {map(({ id, name, email }: Partial) => ( {id} {name} {email} - )(users)} + ))(users)}