divide types into different directories

This commit is contained in:
arttu
2024-12-08 15:36:13 +02:00
parent cb6455e1e1
commit 536907dd2a
29 changed files with 85 additions and 94 deletions
+1 -3
View File
@@ -8,7 +8,6 @@ WORKDIR /usr/src/app
USER node
COPY --chown=node frontend/src/shared /usr/src/app/frontend/src/shared/
COPY --chown=node frontend/src/types.ts /usr/src/app/frontend/src/types.ts
COPY --chown=node backend/package.json backend/
COPY --chown=node backend/package-lock.json backend/
COPY --chown=node backend/prisma/schema.prisma backend
@@ -39,8 +38,7 @@ RUN chown node:node /usr/src/app -R
WORKDIR /usr/src/app
USER node
COPY --from=backend-build --chown=node /usr/src/app/frontend/src/shared/types.d.ts ../frontend/src/shared/types.d.ts
COPY --from=backend-build --chown=node /usr/src/app/frontend/src/types.ts ../frontend/src/types.ts
COPY --from=backend-build --chown=node /usr/src/app/frontend/src/shared/ ../frontend/src/shared/
COPY --from=backend-build --chown=node /usr/src/app/backend/build .
COPY --from=backend-build --chown=node /usr/src/app/backend/node_modules ./backend/node_modules
COPY --from=backend-build --chown=node /usr/src/app/backend/prisma ./backend/prisma
+1 -1
View File
@@ -16,7 +16,7 @@ describe('Logging in', () => {
expect(result.status).toEqual(200)
expect(result.body.username).toEqual('testSu')
expect(result.body.role).toEqual(1) // frontend/src/types: Role enum
expect(result.body.role).toEqual(1) // frontend/src/shared/types: Role enum
expect(result.body.isFirstLogin).toEqual(undefined)
})
+1 -1
View File
@@ -24,7 +24,7 @@ import { ENABLE_WRITE, RUNNING_ENV } from './utils/config'
import { tokenExtractor, userExtractor } from './middlewares/authenticator'
import { errorHandler } from './middlewares/errorHandler'
import { requireOneOf } from './middlewares/authorizer'
import { Role } from './../../frontend/src/types'
import { Role } from './../../frontend/src/shared/types'
import { blockWriteRequests } from './middlewares/misc'
import testRouter from './routes/test'
+1 -2
View File
@@ -2,8 +2,7 @@ import { Middleware } from '../types'
import { SECRET } from '../utils/config'
import jwt, { Secret, TokenExpiredError } from 'jsonwebtoken'
import { nowDb } from '../utils/db'
import { User } from '../../../frontend/src/shared/types'
import { Role } from '../../../frontend/src/types'
import { User, Role } from '../../../frontend/src/shared/types'
/*
This allows extractors to add user and token to request
+1 -1
View File
@@ -1,4 +1,4 @@
import { Role } from '../../../frontend/src/types'
import { Role } from '../../../frontend/src/shared/types'
import { Middleware } from '../types'
export class AccessError extends Error {
+1 -2
View File
@@ -1,9 +1,8 @@
import { Request, Router } from 'express'
import { getAllLocalities, getLocalityDetails, validateEntireLocality } from '../services/locality'
import { fixBigInt } from '../utils/common'
import { EditDataType, EditMetaData, LocalityDetailsType } from '../../../frontend/src/shared/types'
import { EditDataType, EditMetaData, LocalityDetailsType, Role } from '../../../frontend/src/shared/types'
import { requireOneOf } from '../middlewares/authorizer'
import { Role } from '../../../frontend/src/types'
import { deleteLocality, writeLocality } from '../services/write/locality'
const router = Router()
+1 -1
View File
@@ -1,6 +1,6 @@
import { Router } from 'express'
import { getAllPersons, getPersonDetails } from '../services/person'
import { Role } from '../../../frontend/src/types'
import { Role } from '../../../frontend/src/shared/types'
import { requireOneOf } from '../middlewares/authorizer'
const router = Router()
+1 -1
View File
@@ -1,7 +1,7 @@
import { Router } from 'express'
import { getAllProjects, getProjectDetails } from '../services/project'
import { requireOneOf } from '../middlewares/authorizer'
import { Role } from '../../../frontend/src/types'
import { Role } from '../../../frontend/src/shared/types'
const router = Router()
+1 -2
View File
@@ -10,8 +10,7 @@ import {
getJournalById,
} from '../services/reference'
import { requireOneOf } from '../middlewares/authorizer'
import { Role } from '../../../frontend/src/types'
import { EditMetaData, ReferenceDetailsType, EditDataType } from '../../../frontend/src/shared/types'
import { Role, EditMetaData, ReferenceDetailsType, EditDataType } from '../../../frontend/src/shared/types'
import { deleteReference, writeReference } from '../services/write/reference'
const router = Router()
+1 -1
View File
@@ -1,7 +1,7 @@
import { Router } from 'express'
import { getAllRegions, getRegionDetails } from '../services/region'
import { requireOneOf } from '../middlewares/authorizer'
import { Role } from '../../../frontend/src/types'
import { Role } from '../../../frontend/src/shared/types'
const router = Router()
+1 -2
View File
@@ -1,10 +1,9 @@
import { Request, Router } from 'express'
import { getAllSpecies, getSpeciesDetails, validateEntireSpecies } from '../services/species'
import { fixBigInt } from '../utils/common'
import { EditMetaData, SpeciesDetailsType } from '../../../frontend/src/shared/types'
import { EditMetaData, SpeciesDetailsType, Role } from '../../../frontend/src/shared/types'
import { deleteSpecies, writeSpecies } from '../services/write/species'
import { requireOneOf } from '../middlewares/authorizer'
import { Role } from '../../../frontend/src/types'
const router = Router()
+1 -2
View File
@@ -1,6 +1,5 @@
import { Request, Router } from 'express'
import { EditDataType, EditMetaData, TimeBoundDetailsType } from '../../../frontend/src/shared/types'
import { Role } from '../../../frontend/src/types'
import { EditDataType, EditMetaData, TimeBoundDetailsType, Role } from '../../../frontend/src/shared/types'
import { requireOneOf } from '../middlewares/authorizer'
import {
getAllTimeBounds,
+1 -2
View File
@@ -1,6 +1,5 @@
import { Request, Router } from 'express'
import { EditDataType, EditMetaData, TimeUnitDetailsType } from '../../../frontend/src/shared/types'
import { Role } from '../../../frontend/src/types'
import { EditDataType, EditMetaData, TimeUnitDetailsType, Role } from '../../../frontend/src/shared/types'
import { requireOneOf } from '../middlewares/authorizer'
import { getAllSequences } from '../services/sequence'
import {
+1 -1
View File
@@ -6,7 +6,7 @@ import * as bcrypt from 'bcrypt'
import { nowDb } from '../utils/db'
import { getRole } from '../middlewares/authenticator'
import { AccessError } from '../middlewares/authorizer'
import { Role } from '../../../frontend/src/types'
import { Role } from '../../../frontend/src/shared/types'
import md5 from 'md5'
const router = Router()
+1 -2
View File
@@ -1,5 +1,4 @@
import { User, CrossSearch } from '../../../frontend/src/shared/types'
import { Role } from '../../../frontend/src/types'
import { User, CrossSearch, Role } from '../../../frontend/src/shared/types'
import { nowDb } from '../utils/db'
import {
generateFilteredCrossSearchSql,
+1 -2
View File
@@ -1,5 +1,4 @@
import { EditDataType, EditMetaData, LocalityDetailsType, User } from '../../../frontend/src/shared/types'
import { Role } from '../../../frontend/src/types'
import { EditDataType, EditMetaData, LocalityDetailsType, User, Role } from '../../../frontend/src/shared/types'
import { validateLocality } from '../../../frontend/src/shared/validators/locality'
import { ValidationObject, referenceValidator } from '../../../frontend/src/shared/validators/validator'
import Prisma from '../../prisma/generated/now_test_client'
@@ -1,7 +1,6 @@
import { PoolConnection } from 'mariadb'
import { User } from '../../../frontend/src/shared/types'
import { User, Role } from '../../../frontend/src/shared/types'
import { NOW_DB_NAME } from '../utils/config'
import { Role } from '../../../frontend/src/types'
import { pool } from '../utils/db'
const getExportList = async (
+1 -1
View File
@@ -1,8 +1,8 @@
import { EditDataType, LocalityDetailsType, Reference, User } from '../../../../frontend/src/shared/types'
import { getHomininSkeletalRemains } from '../../../../frontend/src/types'
import { NOW_DB_NAME } from '../../utils/config'
import { WriteHandler } from './writeOperations/writeHandler'
import { getFieldsOfTables } from '../../utils/db'
import { getHomininSkeletalRemains } from '../../../../frontend/src/types'
import { getLocalityDetails, filterDuplicateLocalitySpecies } from '../locality'
import { ActionType } from './writeOperations/types'
import { makeListRemoved, fixRadioSelection } from './writeOperations/utils'
@@ -1,7 +1,7 @@
import { Box, TextField } from '@mui/material'
import { EditingModal } from './EditingModal'
import { useForm } from 'react-hook-form'
import { EditDataType, Editable } from '@/shared/types'
import { Editable, EditDataType } from '@/shared/types'
import { useDetailContext } from '../Context/DetailContext'
export type EditingFormField = { name: string; label: string; required?: boolean }
+1 -1
View File
@@ -1,6 +1,6 @@
import { useUser } from '@/hooks/user'
import { useEmailMutation } from '@/redux/emailReducer'
import { Role } from '@/types'
import { Role } from '@/shared/types'
import { Box, Button, Divider, Stack, TextField, Typography } from '@mui/material'
import { useState } from 'react'
+1 -1
View File
@@ -4,7 +4,7 @@ import { useDispatch } from 'react-redux'
import { clearUser } from '../redux/userReducer'
import { api } from '../redux/api'
import { MouseEvent, useState } from 'react'
import { Role } from '@/types'
import { Role } from '@/shared/types'
import { useUser } from '@/hooks/user'
import { ENV } from '@/util/config'
import { useNotify } from '@/hooks/notification'
+1 -1
View File
@@ -3,7 +3,7 @@ import { useParams } from 'react-router-dom'
import { ReactNode, createContext, useContext, useState, Context } from 'react'
import { useUser } from '@/hooks/user'
import { Box } from '@mui/material'
import { Role } from '@/types'
import { Role } from '@/shared/types'
import { UserState } from '@/redux/userReducer'
import { ENABLE_WRITE } from '@/util/config'
+1 -1
View File
@@ -7,6 +7,7 @@ import {
PersonDetailsType,
ProjectDetailsType,
RegionDetails as RegionDetailsType,
Role,
} from '@/shared/types'
import { CrossSearchTable } from './CrossSearch/CrossSearchTable'
import { LocalityDetails } from './Locality/LocalityDetails'
@@ -26,7 +27,6 @@ import { ProjectTable } from './Project/ProjectTable'
import { ProjectDetails } from './Project/ProjectDetails'
import { RegionTable } from './Region/RegionTable'
import { RegionDetails } from './Region/RegionDetails'
import { Role } from '@/types'
import { UserState } from '@/redux/userReducer'
const noRights: EditRights = {}
+1 -1
View File
@@ -1,6 +1,6 @@
import { createSlice, PayloadAction } from '@reduxjs/toolkit'
import { api } from '@/redux/api'
import { Role } from '@/types'
import { Role } from '@/shared/types'
export type LoginResponse = {
token: string
@@ -1,44 +1,8 @@
import * as Prisma from '../../../backend/prisma/generated/now_test_client/default'
import * as LogPrisma from '../../../backend/prisma/generated/now_log_test_client/default'
import { Role } from '../types'
export type User = {
username: string
role: Role
userId: number
initials: string
}
/* This makes all fields optional, except for array-type fields.
Also wraps the objects inside arrays as Editable, adding rowState-field in them.
Applies itself recursively to all nested objects even inside arrays. */
export type EditDataType<T> = T extends object
? T extends readonly unknown[]
? { [I in keyof T]: Editable<EditDataType<T[I]>> }
: { [K in keyof T as T[K] extends readonly unknown[] ? K : never]: EditDataType<T[K]> } & {
[K in keyof T as T[K] extends readonly unknown[] ? never : K]?: EditDataType<T[K]>
} extends infer U
? { [K in keyof U]: U[K] }
: never
: T
// Changes all bigints to number type including in nested objects
export type FixBigInt<T> = {
[K in keyof T]: T[K] extends bigint | null
? number | null
: T[K] extends (infer U)[]
? FixBigInt<U>[]
: T[K] extends object
? FixBigInt<T[K]>
: T[K]
}
import * as Prisma from '../../../../backend/prisma/generated/now_test_client/default'
import * as LogPrisma from '../../../../backend/prisma/generated/now_log_test_client/default'
import { Editable, FixBigInt, RowState } from './util'
export type SpeciesType = FixBigInt<Prisma.com_species>
export type RowState = 'new' | 'removed' | 'cancelled' | 'clean'
// Use this for fields that include array that has to be edited by EditableTable.
// For example see LocalityDetails: museums field
export type Editable<T> = T & { rowState?: RowState }
export type SedimentaryStructureValues = Prisma.now_ss_values
export type CollectingMethod = Prisma.now_coll_meth
export type LocalityProject = Prisma.now_plr & { now_proj: Prisma.now_proj }
@@ -291,16 +255,6 @@ export type ReferenceAuthorType = {
data_id?: number
}
export type ValidationErrors = {
status: string
data: ValidationErrorItem[]
}
type ValidationErrorItem = {
name: string
error: string
}
type Geoname = {
adminCode01: string
lng: number
+3
View File
@@ -0,0 +1,3 @@
export * from './data'
export * from './misc'
export * from './util'
+26
View File
@@ -0,0 +1,26 @@
export enum Role {
Admin = 1,
EditUnrestricted = 2,
EditRestricted = 3,
NowOffice = 4,
Project = 5,
ProjectPrivate = 6,
ReadOnly = 7,
}
export type User = {
username: string
role: Role
userId: number
initials: string
}
export type ValidationErrors = {
status: string
data: ValidationErrorItem[]
}
type ValidationErrorItem = {
name: string
error: string
}
+29
View File
@@ -0,0 +1,29 @@
/* This makes all fields optional, except for array-type fields.
Also wraps the objects inside arrays as Editable, adding rowState-field in them.
Applies itself recursively to all nested objects even inside arrays. */
export type EditDataType<T> = T extends object
? T extends readonly unknown[]
? { [I in keyof T]: Editable<EditDataType<T[I]>> }
: { [K in keyof T as T[K] extends readonly unknown[] ? K : never]: EditDataType<T[K]> } & {
[K in keyof T as T[K] extends readonly unknown[] ? never : K]?: EditDataType<T[K]>
} extends infer U
? { [K in keyof U]: U[K] }
: never
: T
// Changes all bigints to number type including in nested objects
export type FixBigInt<T> = {
[K in keyof T]: T[K] extends bigint | null
? number | null
: T[K] extends (infer U)[]
? FixBigInt<U>[]
: T[K] extends object
? FixBigInt<T[K]>
: T[K]
}
export type RowState = 'new' | 'removed' | 'cancelled' | 'clean'
// Use this for fields that include array that has to be edited by EditableTable.
// For example see LocalityDetails: museums field
export type Editable<T> = T & { rowState?: RowState }
-10
View File
@@ -1,13 +1,3 @@
export enum Role {
Admin = 1,
EditUnrestricted = 2,
EditRestricted = 3,
NowOffice = 4,
Project = 5,
ProjectPrivate = 6,
ReadOnly = 7,
}
import { EditDataType, LocalityDetailsType } from './shared/types'
export const calculateMeanHypsodonty = (locality: LocalityDetailsType) => {