Skip to content
Merged

merge #1083

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
182 commits
Select commit Hold shift + click to select a range
636af2a
chore: remove timeout for long duration csv uploads
david-roper Dec 4, 2024
f41ebd2
chore: add message when there is a large amount of entries to process
david-roper Dec 4, 2024
71d777f
chore: fix translation
david-roper Dec 5, 2024
7d75838
chore: use createMany for instrument records to improve performance #…
david-roper Dec 5, 2024
bbbb72a
fix: package resolution issue caused by DS_Store
joshunrau Dec 9, 2024
df03e66
Merge branch 'DouglasNeuroInformatics:main' into large-upload-fix
david-roper Dec 9, 2024
4c4ec4e
feat: add loading screen while waiting for mutateAsync to complete ax…
david-roper Dec 9, 2024
a203699
chore: provide error message in notification
david-roper Dec 10, 2024
962b835
chore: add new line to error msg #1058
david-roper Dec 10, 2024
6b38c00
chore: deal with potential race condition in createSubjectIfNotFound …
david-roper Dec 10, 2024
00bcf66
chore: publish runtime v1.6.2
joshunrau Dec 11, 2024
072100c
fix: allow legacy instrument properties
joshunrau Dec 11, 2024
0770206
chore: publish runtime v1.6.3
joshunrau Dec 11, 2024
18d15bc
chore: update linting config
joshunrau Dec 11, 2024
15f3617
chore: improve error resolving of prisma errors
david-roper Dec 12, 2024
2ac2d80
fix: adjust fullscreen target
joshunrau Dec 12, 2024
4cf2fc9
fix: add canvas-wrapper to breakout task
joshunrau Dec 12, 2024
c8dd366
fix: scale canvas for hidpi
joshunrau Dec 12, 2024
e212113
fix: add scaling
joshunrau Dec 12, 2024
8b17ec5
style: variable
joshunrau Dec 12, 2024
e5d03ec
refactor: breakout-task
joshunrau Dec 12, 2024
96dbf2e
refactor: pass root
joshunrau Dec 12, 2024
439cfc0
feat: add start button to task
joshunrau Dec 12, 2024
a2a5210
fix: inversion of strict mode in playground
joshunrau Dec 17, 2024
8e99fc6
fix: add typescript libraries to javascript model
joshunrau Dec 17, 2024
8a85c86
fix: stringify issue
joshunrau Dec 17, 2024
27c91ad
chore: publish v1.8.2
joshunrau Dec 17, 2024
72375fc
Merge pull request #1061 from joshunrau/small-fixes
joshunrau Dec 17, 2024
e49155f
Merge pull request #1057 from david-roper/large-upload-fix
joshunrau Dec 17, 2024
9d59cb3
build(deps-dev): bump astro from 4.16.12 to 4.16.17
dependabot[bot] Dec 18, 2024
43b5f0c
Merge pull request #1062 from DouglasNeuroInformatics/dependabot/npm_…
joshunrau Dec 18, 2024
6785366
fix: issue cause by alpine 3.16
joshunrau Dec 19, 2024
37117fe
Merge pull request #1063 from joshunrau/fix-build
joshunrau Dec 19, 2024
dcd8793
chore: revert "fix: issue cause by alpine 3.16"
joshunrau Dec 19, 2024
2f15c58
fix: install openssl1.1-compat
joshunrau Dec 19, 2024
dd2a2d5
Merge pull request #1065 from joshunrau/openssl
joshunrau Dec 19, 2024
4898774
fix: switch from alpine to debian
joshunrau Dec 19, 2024
34755d8
Merge pull request #1066 from joshunrau/openssl
joshunrau Dec 19, 2024
ef00001
feat: add API_RESPONSE_DELAY env variable
joshunrau Dec 19, 2024
b29f71e
feat: add delay middleware
joshunrau Dec 19, 2024
a0ae028
feat: add WithFallback component
joshunrau Dec 19, 2024
9de5086
fix: add WithFallback to data hub page
joshunrau Dec 19, 2024
da558a4
refactor: use WithLoading in Summary
joshunrau Dec 19, 2024
b63769e
fix: increase delay duration
joshunrau Dec 19, 2024
1feaf24
refactor: pass group form props as data
joshunrau Dec 19, 2024
6cf0d00
refactor: use WithFallback in ManageGroup Page
joshunrau Dec 19, 2024
fe5a7f8
build(deps-dev): bump astro from 4.16.17 to 4.16.18
dependabot[bot] Dec 19, 2024
f619623
fix: remove location force render from layout
joshunrau Dec 19, 2024
bdab885
fix: reduce delay
joshunrau Dec 19, 2024
21cf080
Merge pull request #1068 from joshunrau/qol
joshunrau Dec 19, 2024
e381e21
Merge pull request #1067 from DouglasNeuroInformatics/dependabot/npm_…
joshunrau Dec 19, 2024
817c1cf
fix: initial values in start session form
joshunrau Dec 19, 2024
d7a64aa
chore: publish v1.8.3
joshunrau Dec 19, 2024
2eed15e
Merge pull request #1069 from joshunrau/fix-session-form
joshunrau Dec 19, 2024
99bd8b6
fix: add permission notice
joshunrau Dec 20, 2024
735dab4
fix: remove experimental flag for user management
joshunrau Dec 20, 2024
594966f
refactor: update form
joshunrau Dec 20, 2024
f85212d
refactor: pass data
joshunrau Dec 20, 2024
11c6060
feat: allow updating group
joshunrau Dec 20, 2024
9fe1955
refactor: remove description
joshunrau Dec 20, 2024
0e3f41c
fix: scroll
joshunrau Dec 20, 2024
d00d720
chore: update libui
joshunrau Dec 20, 2024
aa823d7
refactor: update user form
joshunrau Dec 23, 2024
32d58d0
chore: update libjs
joshunrau Dec 23, 2024
e444b70
refactor: rename and export $AdditionalUserPermissions
joshunrau Dec 23, 2024
70b8193
refactor: export $UserPermission
joshunrau Dec 23, 2024
ebea1d4
chore: update libui
joshunrau Dec 23, 2024
b026caf
fix: add custom refine for user form
joshunrau Dec 23, 2024
d954422
chore: update deps
joshunrau Dec 23, 2024
b763308
fix: add group connect
joshunrau Dec 27, 2024
f58a3da
fix: optional initialValues
joshunrau Dec 27, 2024
dc63484
docs: add admin to storybook
joshunrau Dec 27, 2024
e049523
docs: add UpdateUserForm stories
joshunrau Dec 27, 2024
532ce49
chore: bump libui
joshunrau Dec 30, 2024
9bb3c90
Merge branch 'main' into update-group
joshunrau Dec 30, 2024
d73f253
Merge pull request #1070 from joshunrau/update-group
joshunrau Dec 30, 2024
e21053a
fix: use WithFallback for setup
joshunrau Dec 31, 2024
7bc6f4f
refactor: remove SetupProvider from App
joshunrau Dec 31, 2024
c7a6586
refactor: simplify setup
joshunrau Dec 31, 2024
9172de2
fix: reimplement SetupProvider
joshunrau Dec 31, 2024
ef092ff
fix: issue where user can create multiple sessions on slow server
joshunrau Dec 31, 2024
8ae69d8
chore: bump libui
joshunrau Dec 31, 2024
666a1d0
refactor: use suspendWhileSubmitting on StartSessionForm
joshunrau Dec 31, 2024
41002c0
chore: update libui
joshunrau Jan 1, 2025
70537b0
chore: update libui
joshunrau Jan 1, 2025
2d82d5c
chore: update libui
joshunrau Jan 2, 2025
6fa1b41
refactor: export function
joshunrau Jan 2, 2025
612a323
fix: suspend on submit for subject assignments page
joshunrau Jan 2, 2025
13f936e
chore: remove dead code
joshunrau Jan 2, 2025
9e65696
refactor: remove dead code
joshunrau Jan 2, 2025
74ce603
fix: allow initialValues to be undefined
joshunrau Jan 2, 2025
cc51295
fix: export user permission type
joshunrau Jan 2, 2025
bfd30c4
chore: temporarily link libui
joshunrau Jan 2, 2025
3a1b40f
fix: type error in UpdateUserForm
joshunrau Jan 2, 2025
bf6f749
refactor: export InstrumentCardInfo
joshunrau Jan 2, 2025
45e61fc
refactor: create TranslatedInstrumentInfo
joshunrau Jan 3, 2025
47798ab
refactor: add supported languages to translation
joshunrau Jan 3, 2025
2a5fbd6
docs: add stories
joshunrau Jan 3, 2025
2c0f673
chore: replace framer-motion with motion in playground
joshunrau Jan 3, 2025
ef9e526
chore: replace framer-motion with motion in react-core
joshunrau Jan 3, 2025
830bc08
chore: replace framer-motion with motion in web
joshunrau Jan 3, 2025
7f90a97
refactor: instrument showcase base
joshunrau Jan 3, 2025
402b27b
refactor: add InstrumentKindDropdown
joshunrau Jan 3, 2025
e98e1ed
fix: typo
joshunrau Jan 3, 2025
4bcfcaa
refactor: move types
joshunrau Jan 3, 2025
2e5daa7
chore: add InstrumentKindDropdown to dropdown
joshunrau Jan 3, 2025
873f288
chore: implement filter on kind
joshunrau Jan 3, 2025
01fabba
chore: implement filter on tags
joshunrau Jan 3, 2025
5f1c7ce
chore: add InstrumentLanguageDropdown
joshunrau Jan 3, 2025
2641115
feat: finish new InstrumentShowcase
joshunrau Jan 3, 2025
0cebead
fix: issue with InstrumentCard heading color
joshunrau Jan 3, 2025
ce8b31a
fix: add suspend to identification form
joshunrau Jan 3, 2025
eec0775
feat: add ForceClearQueryCacheProvider
joshunrau Jan 3, 2025
cc9d0cf
chore: reverse local link libui
joshunrau Jan 3, 2025
d00aca4
Merge pull request #1071 from joshunrau/refine
joshunrau Jan 3, 2025
400ffb6
chore: add sample csv section
david-roper Jan 7, 2025
952d92a
chore: add sample csv template table
david-roper Jan 7, 2025
d1da7a1
chore: add sample table and example valid entries for it
david-roper Jan 7, 2025
abf9503
chore: remove ...
david-roper Jan 7, 2025
c6a3dc2
chore: adding emphasis on examples
david-roper Jan 7, 2025
fcb45fe
chore: corrections in spelling
david-roper Jan 7, 2025
3eeb02c
fix: set default background color for interactive task to white
joshunrau Jan 8, 2025
434d7f5
fix: set default value for API_RESPONSE_DELAY to undefined
joshunrau Jan 8, 2025
cfbc156
fix: issues with number parsing
joshunrau Jan 8, 2025
d0b307a
chore: increment version
joshunrau Jan 8, 2025
0a0a1a3
Merge pull request #1073 from joshunrau/playground-background
joshunrau Jan 8, 2025
ed0e7bc
Merge pull request #1072 from david-roper/add-csv-doc-example
joshunrau Jan 8, 2025
ecd360f
chore: deal with shape of zodArray.type TODO #995
david-roper Jan 9, 2025
eed8e3d
chore: deal with undefined record TODO #995
david-roper Jan 9, 2025
ce3afb2
chore: deal with whitespace and trailing semicolon TODO via interpret…
david-roper Jan 9, 2025
def4e91
fix: add try catch for errors for template csv download
david-roper Jan 10, 2025
7e3e1e1
chore: catch errors thrown by extract set and record array functions
david-roper Jan 10, 2025
c67fd9b
chore: typeguard for instrument validation schema
david-roper Jan 13, 2025
1cc52ef
chore: catch specific undefined/ unsuccessful record array data error
david-roper Jan 13, 2025
7e91e93
chore: add better name for innerSchema def variable
david-roper Jan 14, 2025
8a8cd1f
chore: make csv upload error more descriptive
david-roper Jan 14, 2025
8fec855
chore: add specified error message for undefined record array keys
david-roper Jan 14, 2025
f134ad2
fix: add error message on upload fail
joshunrau Jan 14, 2025
96e8c46
chore: make error message describe issue and path for all possible zo…
david-roper Jan 14, 2025
be0ffb4
fix: allow uploading zip with single directory
joshunrau Jan 14, 2025
6a4b708
feat: support importing mp4 in instruments
joshunrau Jan 14, 2025
3a88ad7
chore: remove unused comments and solved TODOs
david-roper Jan 14, 2025
5f78c5f
docs: add example with video
joshunrau Jan 14, 2025
514293c
fix: increase seconds remaining
joshunrau Jan 14, 2025
1113178
Merge pull request #1075 from joshunrau/video
joshunrau Jan 14, 2025
f9b4c06
chore: rename cat video task
joshunrau Jan 15, 2025
362c3cf
fix: only save user instruments
joshunrau Jan 15, 2025
1cd38e2
feat: add json support for instruments
joshunrau Jan 15, 2025
61759c2
Merge pull request #1076 from joshunrau/json
joshunrau Jan 15, 2025
ca774c1
chore: increment version
joshunrau Jan 16, 2025
aed3c5e
Merge pull request #1077 from joshunrau/v1.8.5
joshunrau Jan 16, 2025
cff813c
chore: trim whitespaces off csv entries, make regex exlude whitespace…
david-roper Jan 16, 2025
0e798ec
chore: error message now include column name, made subjectid validati…
david-roper Jan 16, 2025
e8c8381
chore: added Zod Validation Schema type guard, refactor error throwing
david-roper Jan 16, 2025
db39508
chore: small improvements to comments
david-roper Jan 17, 2025
6e82d01
Merge branch 'DouglasNeuroInformatics:main' into working-on-todos
david-roper Jan 17, 2025
3749d46
chore: remove redundant unknown type from error catch
david-roper Jan 20, 2025
17482eb
chore: format with prettier
david-roper Jan 20, 2025
f78c278
chore: format with prettier
david-roper Jan 20, 2025
1e042d5
chore: remove redundant unknown annotation in error catching
david-roper Jan 20, 2025
9f11f10
chore: add cause value to createUploadTemplateCsv default error
david-roper Jan 20, 2025
aaaa1fa
Update apps/web/src/features/upload/utils.ts
david-roper Jan 20, 2025
ea612f8
chore: better error msg for empty column name
david-roper Jan 21, 2025
1d1b531
Merge pull request #1078 from david-roper/working-on-todos
joshunrau Jan 21, 2025
d736812
chore(deps-dev): bump vite from 5.4.11 to 5.4.12
dependabot[bot] Jan 22, 2025
84e7bb1
Merge pull request #1079 from DouglasNeuroInformatics/dependabot/npm_…
joshunrau Jan 22, 2025
e9ea336
chore: update typescript
joshunrau Jan 22, 2025
74dc665
chore: adjust file extensions
joshunrau Jan 22, 2025
f95aa5f
chore: apply non-breaking dependency updates
joshunrau Jan 22, 2025
6da6d92
fix: type issue in astro
joshunrau Jan 22, 2025
7e1dbcf
chore: move vite to catalog
joshunrau Jan 22, 2025
a9f6e55
chore: bump libnest
joshunrau Jan 22, 2025
7d6f440
fix: add GLOBAL_PROXY_SHIM to bundle
joshunrau Jan 22, 2025
5963fb5
feat: add __ODC_BUNDLER_ERROR_CONTEXT
joshunrau Jan 22, 2025
f13394f
fix: add file context to globalThis
joshunrau Jan 22, 2025
baaacc6
chore: reinstall deps
joshunrau Jan 22, 2025
ea794b8
Merge pull request #1080 from joshunrau/patches
joshunrau Jan 22, 2025
fd1806e
refactor: rename transformStaticImports
joshunrau Jan 22, 2025
e24c448
feat: add globalThis.__import
joshunrau Jan 22, 2025
a915017
Merge pull request #1081 from joshunrau/patches
joshunrau Jan 22, 2025
af8dd41
fix: use __import for already dynamic imports
joshunrau Jan 22, 2025
7ea5bc2
Merge pull request #1082 from joshunrau/patches
joshunrau Jan 22, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .env.template
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ PLAYGROUND_DEV_SERVER_PORT=3750
GATEWAY_DEV_SERVER_PORT=3500
# The port to use for the Vite (full web app) development server
WEB_DEV_SERVER_PORT=3000

# Set an arbitrary delay (in milliseconds) for all responses (useful for testing suspense)
API_RESPONSE_DELAY=
# If set to 'true' and NODE_ENV === 'development', then login is automated
VITE_DEV_BYPASS_AUTH=false
# The username to use if VITE_DEV_BYPASS_AUTH is set to true
Expand All @@ -87,6 +88,8 @@ VITE_DEV_PASSWORD=Password12345678
API_BASE_URL=http://localhost:5500
# The number of miliseconds to delay the result of HTTP requests in development
VITE_DEV_NETWORK_LATENCY=0
# Whether to force clear queries when the pathname changes
VITE_DEV_FORCE_CLEAR_QUERY_CACHE=false
# Plausable analytics config (optional, set both to an empty string to disable)
PLAUSIBLE_BASE_URL=
PLAUSIBLE_WEB_DATA_DOMAIN=
Expand Down
2 changes: 1 addition & 1 deletion apps/api/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:iron-alpine AS base
FROM node:iron AS base
WORKDIR /app
ARG RELEASE_VERSION
ENV GATEWAY_DATABASE_URL="file:/dev/null"
Expand Down
16 changes: 8 additions & 8 deletions apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@
"@douglasneuroinformatics/libnest": "catalog:",
"@douglasneuroinformatics/libpasswd": "catalog:",
"@douglasneuroinformatics/libstats": "catalog:",
"@faker-js/faker": "^9.0.0",
"@faker-js/faker": "^9.4.0",
"@nestjs/axios": "^3.0.3",
"@nestjs/common": "^10.4.1",
"@nestjs/config": "^3.2.3",
"@nestjs/core": "^10.4.1",
"@nestjs/jwt": "^10.2.0",
"@nestjs/mapped-types": "2.0.5",
"@nestjs/mapped-types": "2.1.0",
"@nestjs/passport": "^10.0.3",
"@nestjs/platform-express": "^10.4.1",
"@nestjs/swagger": "^7.4.0",
"@nestjs/throttler": "^6.2.1",
"@nestjs/throttler": "^6.3.0",
"@opendatacapture/demo": "workspace:*",
"@opendatacapture/instrument-library": "workspace:*",
"@opendatacapture/instrument-utils": "workspace:*",
Expand All @@ -47,9 +47,9 @@
"@opendatacapture/subject-utils": "workspace:*",
"@prisma/client": "catalog:",
"axios": "catalog:",
"express": "^4.19.2",
"express": "^4.21.2",
"lodash-es": "workspace:lodash-es__4.x@*",
"mongodb": "^6.8.1",
"mongodb": "^6.12.0",
"passport": "^0.7.0",
"passport-jwt": "4.0.1",
"reflect-metadata": "^0.1.14",
Expand All @@ -62,15 +62,15 @@
"@nestjs/testing": "^10.4.1",
"@opendatacapture/instrument-stubs": "workspace:*",
"@types/express": "^4.17.21",
"@types/passport": "^1.0.16",
"@types/passport": "^1.0.17",
"@types/passport-jwt": "^4.0.1",
"@types/supertest": "^6.0.2",
"concurrently": "^9.0.0",
"concurrently": "^9.1.2",
"esbuild": "catalog:",
"esbuild-plugin-tsc": "^0.4.0",
"nodemon": "catalog:",
"prisma": "catalog:",
"prisma-json-types-generator": "^3.0.4",
"prisma-json-types-generator": "^3.2.2",
"supertest": "^7.0.0",
"type-fest": "workspace:type-fest__4.x@*"
},
Expand Down
13 changes: 12 additions & 1 deletion apps/api/src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { CryptoModule } from '@douglasneuroinformatics/libnest/crypto';
import { LoggingModule } from '@douglasneuroinformatics/libnest/logging';
import { Module } from '@nestjs/common';
import type { MiddlewareConsumer, NestModule } from '@nestjs/common';
import { APP_GUARD } from '@nestjs/core';
import { ThrottlerGuard, ThrottlerModule } from '@nestjs/throttler';

Expand All @@ -10,6 +11,7 @@ import { AuthenticationGuard } from './auth/guards/authentication.guard';
import { AuthorizationGuard } from './auth/guards/authorization.guard';
import { ConfigurationModule } from './configuration/configuration.module';
import { ConfigurationService } from './configuration/configuration.service';
import { DelayMiddleware } from './core/middleware/delay.middleware';
import { GatewayModule } from './gateway/gateway.module';
import { GroupsModule } from './groups/groups.module';
import { InstrumentsModule } from './instruments/instruments.module';
Expand Down Expand Up @@ -93,4 +95,13 @@ import { UsersModule } from './users/users.module';
}
]
})
export class AppModule {}
export class AppModule implements NestModule {
constructor(private readonly configurationService: ConfigurationService) {}

configure(consumer: MiddlewareConsumer) {
const isDev = this.configurationService.get('NODE_ENV') === 'development';
if (isDev) {
consumer.apply(DelayMiddleware).forRoutes('*');
}
}
}
19 changes: 15 additions & 4 deletions apps/api/src/configuration/configuration.schema.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { isNumberLike, parseNumber } from '@douglasneuroinformatics/libjs';
import { $BooleanString } from '@opendatacapture/schemas/core';
import { z } from 'zod';

Expand All @@ -10,17 +11,27 @@ const $OptionalURL = z.preprocess(
.transform((arg) => (arg ? new URL(arg) : undefined))
);

const $ParsedNumber = <TSchema extends z.ZodTypeAny>(schema: TSchema) => {
return z.preprocess((arg) => {
if (!isNumberLike(arg)) {
return undefined;
}
return parseNumber(arg);
}, schema);
};

export const $Configuration = z
.object({
API_DEV_SERVER_PORT: z.coerce.number().positive().int().optional(),
API_PROD_SERVER_PORT: z.coerce.number().positive().int().default(80),
API_DEV_SERVER_PORT: $ParsedNumber(z.number().positive().int().optional()),
API_PROD_SERVER_PORT: $ParsedNumber(z.number().positive().int().default(80)),
API_RESPONSE_DELAY: $ParsedNumber(z.number().positive().int().optional()),
DANGEROUSLY_DISABLE_PBKDF2_ITERATION: $BooleanString.default(false),
DEBUG: $BooleanString,
GATEWAY_API_KEY: z.string().min(32),
GATEWAY_DEV_SERVER_PORT: z.coerce.number().positive().int().optional(),
GATEWAY_DEV_SERVER_PORT: $ParsedNumber(z.number().positive().int().optional()),
GATEWAY_ENABLED: $BooleanString,
GATEWAY_INTERNAL_NETWORK_URL: $OptionalURL,
GATEWAY_REFRESH_INTERVAL: z.coerce.number().positive().int(),
GATEWAY_REFRESH_INTERVAL: $ParsedNumber(z.number().positive().int()),
GATEWAY_SITE_ADDRESS: $OptionalURL,
MONGO_DIRECT_CONNECTION: z.string().optional(),
MONGO_REPLICA_SET: z.string().optional(),
Expand Down
18 changes: 18 additions & 0 deletions apps/api/src/core/middleware/delay.middleware.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Injectable, type NestMiddleware } from '@nestjs/common';

import { ConfigurationService } from '@/configuration/configuration.service';

@Injectable()
export class DelayMiddleware implements NestMiddleware {
constructor(private readonly configurationService: ConfigurationService) {}

use(_req: any, _res: any, next: (error?: any) => void) {
const responseDelay = this.configurationService.get('API_RESPONSE_DELAY');
if (!responseDelay) {
return next();
}
setTimeout(() => {
next();
}, responseDelay);
}
}
115 changes: 54 additions & 61 deletions apps/api/src/instrument-records/instrument-records.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type {
LinearRegressionResults,
UploadInstrumentRecordsData
} from '@opendatacapture/schemas/instrument-records';
import type { InstrumentRecordModel, Prisma, SessionModel } from '@prisma/generated-client';
import { type InstrumentRecordModel, Prisma, type SessionModel } from '@prisma/generated-client';
import { isNumber, pickBy } from 'lodash-es';

import { accessibleQuery } from '@/ability/ability.utils';
Expand Down Expand Up @@ -274,91 +274,84 @@ export class InstrumentRecordsService {
);
}

const createdRecordsArray: InstrumentRecordModel[] = [];
const createdSessionsArray: SessionModel[] = [];

try {
for (let i = 0; i < records.length; i++) {
const { data: rawData, date, subjectId } = records[i]!;
await this.createSubjectIfNotFound(subjectId);

const session = await this.sessionsService.create({
date: date,
groupId: groupId ? groupId : null,
subjectData: {
id: subjectId
},
type: 'RETROSPECTIVE'
});
const preProcessedRecords = await Promise.all(
records.map(async (record) => {
const { data: rawData, date, subjectId } = record;

// Validate data
const parseResult = instrument.validationSchema.safeParse(this.parseJson(rawData));
if (!parseResult.success) {
console.error(parseResult.error.issues);
throw new UnprocessableEntityException(
`Data received for record does not pass validation schema of instrument '${instrument.id}'`
);
}

createdSessionsArray.push(session);
// Ensure subject exists
await this.createSubjectIfNotFound(subjectId);

const sessionId = session.id;
const session = await this.sessionsService.create({
date: date,
groupId: groupId ?? null,
subjectData: { id: subjectId },
type: 'RETROSPECTIVE'
});

const parseResult = instrument.validationSchema.safeParse(this.parseJson(rawData));
if (!parseResult.success) {
console.error(parseResult.error.issues);
throw new UnprocessableEntityException(
`Data received for record at index '${i}' does not pass validation schema of instrument '${instrument.id}'`
);
}
createdSessionsArray.push(session);

const createdRecord = await this.instrumentRecordModel.create({
data: {
computedMeasures: instrument.measures
? this.instrumentMeasuresService.computeMeasures(instrument.measures, parseResult.data)
: null,
const computedMeasures = instrument.measures
? this.instrumentMeasuresService.computeMeasures(instrument.measures, parseResult.data)
: null;

return {
computedMeasures,
data: this.serializeData(parseResult.data),
date,
group: groupId
? {
connect: { id: groupId }
}
: undefined,
instrument: {
connect: {
id: instrumentId
}
},
session: {
connect: {
id: sessionId
}
},
subject: {
connect: {
id: subjectId
}
}
}
});
groupId,
instrumentId,
sessionId: session.id,
subjectId
};
})
);

createdRecordsArray.push(createdRecord);
}
} catch (err) {
await this.instrumentRecordModel.deleteMany({
await this.instrumentRecordModel.createMany({
data: preProcessedRecords
});

return this.instrumentRecordModel.findMany({
where: {
id: {
in: createdRecordsArray.map((record) => record.id)
}
groupId,
instrumentId
}
});
} catch (err) {
await this.sessionsService.deleteByIds(createdSessionsArray.map((session) => session.id));
throw err;
}

return createdRecordsArray;
}

private async createSubjectIfNotFound(subjectId: string) {
try {
await this.subjectsService.findById(subjectId);
return await this.subjectsService.findById(subjectId);
} catch (exception) {
if (exception instanceof NotFoundException) {
const addedSubject: CreateSubjectDto = {
id: subjectId
};
await this.subjectsService.create(addedSubject);
try {
return await this.subjectsService.create(addedSubject);
} catch (prismaError) {
if (prismaError instanceof Prisma.PrismaClientKnownRequestError && prismaError.code === 'P2002') {
console.error(prismaError);
return await this.subjectsService.findById(subjectId);
} else {
throw prismaError;
}
}
} else {
throw exception;
}
Expand Down
9 changes: 7 additions & 2 deletions apps/api/src/users/users.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,14 @@ export class UsersService {
return user;
}

async updateById(id: string, data: UpdateUserDto, { ability }: EntityOperationOptions = {}) {
async updateById(id: string, { groupIds, ...data }: UpdateUserDto, { ability }: EntityOperationOptions = {}) {
return this.userModel.update({
data,
data: {
...data,
groups: {
connect: groupIds?.map((id) => ({ id }))
}
},
where: { AND: [accessibleQuery(ability, 'update', 'User')], id }
});
}
Expand Down
2 changes: 1 addition & 1 deletion apps/gateway/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:iron-alpine AS base
FROM node:iron AS base
WORKDIR /app
ARG RELEASE_VERSION
ENV GATEWAY_DATABASE_URL=file:/app/sqlite/gateway.db
Expand Down
14 changes: 7 additions & 7 deletions apps/gateway/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
"@opendatacapture/schemas": "workspace:*",
"@prisma/client": "catalog:",
"axios": "catalog:",
"compression": "^1.7.4",
"express": "^4.19.2",
"compression": "^1.7.5",
"express": "^4.21.2",
"lodash-es": "workspace:lodash-es__4.x@*",
"pino-http": "^10.3.0",
"pino-http": "^10.4.0",
"pino-pretty": "^11.2.2",
"react": "workspace:react__18.x@*",
"react-dom": "workspace:react-dom__18.x@*",
Expand All @@ -42,15 +42,15 @@
"@opendatacapture/vite-plugin-runtime": "workspace:*",
"@types/compression": "^1.7.5",
"@types/express": "^4.17.21",
"@vitejs/plugin-react-swc": "^3.7.0",
"@vitejs/plugin-react-swc": "^3.7.2",
"autoprefixer": "^10.4.20",
"esbuild": "catalog:",
"nodemon": "catalog:",
"postcss": "^8.4.45",
"postcss": "^8.5.1",
"prisma": "catalog:",
"tailwindcss": "^3.4.10",
"tailwindcss": "^3.4.17",
"type-fest": "workspace:type-fest__4.x@*",
"vite": "^5.4.3"
"vite": "catalog:"
},
"trustedDependencies": [
"prisma",
Expand Down
Loading
Loading