Skip to content

Commit 1c7bcfe

Browse files
authored
Merge pull request #999 from joshunrau/fix-error
2 parents 9a8c146 + b31d800 commit 1c7bcfe

29 files changed

Lines changed: 230 additions & 39 deletions

File tree

apps/api/prisma/schema.prisma

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,10 @@ model SessionModel {
190190
// Setup
191191

192192
model SetupStateModel {
193-
createdAt DateTime @default(now()) @db.Date
194-
updatedAt DateTime @updatedAt @db.Date
195-
id String @id @default(auto()) @map("_id") @db.ObjectId
196-
isDemo Boolean
197-
isSetup Boolean
193+
createdAt DateTime @default(now()) @db.Date
194+
updatedAt DateTime @updatedAt @db.Date
195+
id String @id @default(auto()) @map("_id") @db.ObjectId
196+
isDemo Boolean
197+
isExperimentalFeaturesEnabled Boolean?
198+
isSetup Boolean
198199
}

apps/api/src/instrument-records/instrument-records.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { yearsPassed } from '@douglasneuroinformatics/libjs';
2+
import { reviver } from '@douglasneuroinformatics/libjs';
23
import { linearRegression } from '@douglasneuroinformatics/libstats';
34
import { Injectable, NotFoundException, UnprocessableEntityException } from '@nestjs/common';
45
import type { Json, ScalarInstrument } from '@opendatacapture/runtime-core';
@@ -25,7 +26,6 @@ import { SubjectsService } from '@/subjects/subjects.service';
2526
import { VirtualizationService } from '@/virtualization/virtualization.service';
2627

2728
import { InstrumentMeasuresService } from './instrument-measures.service';
28-
import { reviver } from '@douglasneuroinformatics/libjs';
2929

3030
@Injectable()
3131
export class InstrumentRecordsService {
@@ -287,7 +287,7 @@ export class InstrumentRecordsService {
287287

288288
const sessionId = session.id;
289289

290-
const revivedData: Json = JSON.parse(JSON.stringify(data), reviver);
290+
const revivedData = JSON.parse(JSON.stringify(data), reviver) as Json;
291291

292292
if (!instrument.validationSchema.safeParse(revivedData).success) {
293293
throw new UnprocessableEntityException(

apps/api/src/setup/dto/init-app.dto.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ export class InitAppDto implements InitAppOptions {
1111
@ApiProperty()
1212
dummySubjectCount?: number;
1313

14+
@ApiProperty()
15+
enableExperimentalFeatures: boolean;
16+
1417
@ApiProperty()
1518
initDemo: boolean;
1619

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { ValidationSchema } from '@douglasneuroinformatics/libnest/core';
2+
import { ApiProperty } from '@nestjs/swagger';
3+
import { $UpdateSetupStateData } from '@opendatacapture/schemas/setup';
4+
import type { UpdateSetupStateData } from '@opendatacapture/schemas/setup';
5+
6+
@ValidationSchema($UpdateSetupStateData)
7+
export class UpdateSetupStateDto implements UpdateSetupStateData {
8+
@ApiProperty()
9+
isExperimentalFeaturesEnabled?: boolean;
10+
}

apps/api/src/setup/setup.controller.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import { Body, Controller, Get, Post } from '@nestjs/common';
1+
import { Body, Controller, Get, Patch, Post } from '@nestjs/common';
22
import { ApiOperation, ApiTags } from '@nestjs/swagger';
33
import type { SetupState } from '@opendatacapture/schemas/setup';
44

55
import { RouteAccess } from '@/core/decorators/route-access.decorator';
66

77
import { InitAppDto } from './dto/init-app.dto';
8+
import { UpdateSetupStateDto } from './dto/update-setup-state.dto';
89
import { SetupService } from './setup.service';
910

1011
@ApiTags('Setup')
@@ -34,4 +35,14 @@ export class SetupController {
3435
initApp(@Body() initAppDto: InitAppDto): Promise<{ success: boolean }> {
3536
return this.setupService.initApp(initAppDto);
3637
}
38+
39+
@ApiOperation({
40+
description: 'Update the setup state',
41+
summary: 'Update State'
42+
})
43+
@Patch()
44+
@RouteAccess({ action: 'manage', subject: 'all' })
45+
updateState(@Body() data: UpdateSetupStateDto): Promise<Partial<SetupState>> {
46+
return this.setupService.updateState(data);
47+
}
3748
}

apps/api/src/setup/setup.service.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { ForbiddenException, Injectable } from '@nestjs/common';
1+
import { ForbiddenException, Injectable, ServiceUnavailableException } from '@nestjs/common';
22
import { type CreateAdminData } from '@opendatacapture/schemas/setup';
3-
import type { InitAppOptions, SetupState } from '@opendatacapture/schemas/setup';
3+
import type { InitAppOptions, SetupState, UpdateSetupStateData } from '@opendatacapture/schemas/setup';
44

55
import { ConfigurationService } from '@/configuration/configuration.service';
66
import { DemoService } from '@/demo/demo.service';
@@ -27,14 +27,15 @@ export class SetupService {
2727
const savedOptions = await this.getSavedOptions();
2828
return {
2929
isDemo: Boolean(savedOptions?.isDemo),
30+
isExperimentalFeaturesEnabled: Boolean(savedOptions?.isExperimentalFeaturesEnabled),
3031
isGatewayEnabled: this.configurationService.get('GATEWAY_ENABLED'),
3132
isSetup: Boolean(savedOptions?.isSetup),
3233
release: __RELEASE__,
3334
uptime: Math.round(process.uptime())
3435
} satisfies SetupState;
3536
}
3637

37-
async initApp({ admin, dummySubjectCount, initDemo, recordsPerSubject }: InitAppOptions) {
38+
async initApp({ admin, dummySubjectCount, enableExperimentalFeatures, initDemo, recordsPerSubject }: InitAppOptions) {
3839
const isDev = this.configurationService.get('NODE_ENV') === 'development';
3940
const savedOptions = await this.getSavedOptions();
4041
if (savedOptions?.isSetup && !isDev) {
@@ -48,10 +49,25 @@ export class SetupService {
4849
recordsPerSubject: recordsPerSubject ?? 0
4950
});
5051
}
51-
await this.setupStateModel.create({ data: { isDemo: initDemo, isSetup: true } });
52+
await this.setupStateModel.create({
53+
data: { isDemo: initDemo, isExperimentalFeaturesEnabled: enableExperimentalFeatures, isSetup: true }
54+
});
5255
return { success: true };
5356
}
5457

58+
async updateState(data: UpdateSetupStateData): Promise<Partial<SetupState>> {
59+
const setupState = await this.getSavedOptions();
60+
if (!setupState?.isSetup) {
61+
throw new ServiceUnavailableException('Cannot update state before setup');
62+
}
63+
return this.setupStateModel.update({
64+
data,
65+
where: {
66+
id: setupState.id
67+
}
68+
});
69+
}
70+
5571
private async getSavedOptions() {
5672
return await this.setupStateModel.findFirst();
5773
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
declare var message: 'hello';
1+
declare let message: 'hello';

apps/playground/src/store/slices/editor.slice.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export const createEditorSlice: SliceCreator<EditorSlice> = (set, get) => ({
8080
},
8181
updateFile: (name, update) => {
8282
set((state) => {
83-
let index = state.files.findIndex((file) => file.name === name);
83+
const index = state.files.findIndex((file) => file.name === name);
8484
if (index === -1) {
8585
console.error(`Cannot update file '${name}': file does not exist`);
8686
return;

apps/playground/src/vim/adapter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,7 @@ export default class EditorAdapter {
680680
let char = key;
681681
const pos = this.getPos_();
682682
let range = makeRange(pos.lineNumber, pos.column, pos.lineNumber, pos.column + 1);
683-
let forceMoveMarkers = true;
683+
const forceMoveMarkers = true;
684684

685685
if (key.startsWith("'")) {
686686
char = key[1]!;

apps/playground/src/vim/default-key-map.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { KeyMapping } from './types';
22

3-
export let defaultKeymap: KeyMapping[] = [
3+
export const defaultKeymap: KeyMapping[] = [
44
// Key to key mapping. This goes first to make it possible to override
55
// existing mappings.
66
{ keys: '<Left>', toKeys: 'h', type: 'keyToKey' },
@@ -838,4 +838,4 @@ export let defaultKeymap: KeyMapping[] = [
838838
{ keys: ':', type: 'ex' }
839839
];
840840

841-
export let defaultKeymapLength = defaultKeymap.length;
841+
export const defaultKeymapLength = defaultKeymap.length;

0 commit comments

Comments
 (0)