Skip to content

Commit

Permalink
Merge develop branch
Browse files Browse the repository at this point in the history
  • Loading branch information
wsy19961129 committed Jul 12, 2024
2 parents efbd0b6 + 29998a2 commit 3294027
Show file tree
Hide file tree
Showing 16 changed files with 996 additions and 901 deletions.
1 change: 1 addition & 0 deletions .commitlintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module.exports = {
(await getProjects(ctx, projectFilter))
.forEach(element => {
projectNames.add(element);
projectNames.add(element.replaceAll('itmat-', ''));
});
return [
2,
Expand Down
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ indent_size = 4
insert_final_newline = true
trim_trailing_whitespace = true

[.yml]
indent_size = 2

[*.md]
max_line_length = off
trim_trailing_whitespace = false
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@
*.mjsx
*.cjs
*.cjsx
*.yaml
2 changes: 1 addition & 1 deletion SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ currently being supported with security updates.

| Version | Supported |
| ------- | ------------------ |
| 2.5.1 | :white_check_mark: |
| 2.6.0 | :white_check_mark: |
| < 2 | :x: |

## Reporting a Vulnerability
Expand Down
58 changes: 58 additions & 0 deletions dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
version: 2
updates:
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "weekly"
target-branch: "develop"
labels:
- "dependencies"
groups:
nx:
patterns:
- "nx"
- "@nx/*"
- "@jscutlery/semver"
lint:
patterns:
- "eslint*"
- "@typescript-eslint/*"
dev:
patterns:
- "commitlint"
- "@commitlint/*"
- "@swc/*"
- "@svgr/webpack"
- "esbuild*"
- "postcss"
- "prettier"
- "webpack"
- "verdaccio"
- "typscript"
test:
patterns:
- "jsdom"
- "sinon-chrome"
- "jest*"
- "babel-jest"
babel:
patterns:
- "babel*"
- "@babel/*"
types:
patterns:
- "@types/*"
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
target-branch: "develop"
labels:
- "actions"
- package-ecosystem: "docker"
directory: "/"
schedule:
interval: "weekly"
target-branch: "develop"
labels:
- "docker"
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "itmat-broker",
"version": "2.5.1",
"version": "2.6.0",
"private": true,
"license": "MIT",
"scripts": {
Expand Down
69 changes: 33 additions & 36 deletions packages/itmat-cores/src/GraphQLCore/studyCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,22 @@ import { buildPipeline, dataStandardization } from '../utils/query';
import { DBType } from '../database/database';
import { ObjectStore } from '@itmat-broker/itmat-commons';

enum enumV2DataType {
'INT' = 'int',
'DEC' = 'dec',
'STR' = 'str',
'BOOL' = 'bool',
'DATE' = 'date',
'FILE' = 'file',
'JSON' = 'json',
'CAT' = 'cat'
}

export interface CreateFieldInput {
fieldId: string;
fieldName: string
tableName?: string
dataType: string;
dataType: enumV2DataType;
possibleValues?: ICategoricalOption[]
unit?: string
comments?: string
Expand All @@ -28,7 +39,7 @@ export interface EditFieldInput {
fieldId: string;
fieldName: string;
tableName?: string;
dataType: string;
dataType: enumV2DataType;
possibleValues?: ICategoricalOption[]
unit?: string
comments?: string
Expand Down Expand Up @@ -107,28 +118,35 @@ export class StudyCore {
return {
id: el.id,
code: el.code,
description: el.description
description: el.description,
life: {
createdTime: el.life.createdTime,
createdUser: el.life.createdUser,
deletedTime: el.life.deletedTime,
deletedUser: el.life.deletedUser
},
metadata: {}
};
}) : [],
dataType: (() => {
if (field.dataType === enumDataTypes.INTEGER) {
return 'int';
return enumV2DataType.INT;
} else if (field.dataType === enumDataTypes.DECIMAL) {
return 'dec';
return enumV2DataType.DEC;
} else if (field.dataType === enumDataTypes.STRING) {
return 'str';
return enumV2DataType.STR;
} else if (field.dataType === enumDataTypes.BOOLEAN) {
return 'bool';
return enumV2DataType.BOOL;
} else if (field.dataType === enumDataTypes.DATETIME) {
return 'date';
return enumV2DataType.DATE;
} else if (field.dataType === enumDataTypes.FILE) {
return 'file';
return enumV2DataType.FILE;
} else if (field.dataType === enumDataTypes.JSON) {
return 'json';
return enumV2DataType.JSON;
} else if (field.dataType === enumDataTypes.CATEGORICAL) {
return 'cat';
return enumV2DataType.CAT;
} else {
return 'str';
return enumV2DataType.STR;
}
})(),
dateAdded: field.life.createdTime.toString(),
Expand Down Expand Up @@ -654,7 +672,7 @@ export class StudyCore {
error.push(`Data type shouldn't be ${fieldEntry.dataType}: use 'int' for integer, 'dec' for decimal, 'str' for string, 'bool' for boolean, 'date' for datetime, 'file' for FILE, 'json' for json.`);
}
// check possiblevalues to be not-empty if datatype is categorical
if (fieldEntry.dataType === enumDataTypes.CATEGORICAL) {
if (fieldEntry.dataType === enumV2DataType.CAT) {
if (fieldEntry.possibleValues !== undefined && fieldEntry.possibleValues !== null) {
if (fieldEntry.possibleValues.length === 0) {
error.push(`${fieldEntry.fieldId}-${fieldEntry.fieldName}: possible values can't be empty if data type is categorical.`);
Expand All @@ -672,7 +690,7 @@ export class StudyCore {
fieldName: fieldEntry.fieldName,
tableName: null,
dataType: fieldEntry.dataType,
possibleValues: fieldEntry.dataType === enumDataTypes.CATEGORICAL ? fieldEntry.possibleValues : null,
possibleValues: fieldEntry.dataType === enumV2DataType.CAT ? fieldEntry.possibleValues : null,
unit: fieldEntry.unit,
comments: fieldEntry.comments,
metadata: {
Expand Down Expand Up @@ -808,27 +826,6 @@ export class StudyCore {
}
searchField.fieldId = fieldInput.fieldId;
searchField.fieldName = fieldInput.fieldName;
searchField.dataType = (() => {
if (fieldInput.dataType === 'int') {
return enumDataTypes.INTEGER;
} else if (fieldInput.dataType === 'dec') {
return enumDataTypes.DECIMAL;
} else if (fieldInput.dataType === 'str') {
return enumDataTypes.STRING;
} else if (fieldInput.dataType === 'bool') {
return enumDataTypes.BOOLEAN;
} else if (fieldInput.dataType === 'date') {
return enumDataTypes.DATETIME;
} else if (fieldInput.dataType === 'file') {
return enumDataTypes.FILE;
} else if (fieldInput.dataType === 'json') {
return enumDataTypes.JSON;
} else if (fieldInput.dataType === 'cat') {
return enumDataTypes.CATEGORICAL;
} else {
return enumDataTypes.STRING;
}
})();
if (fieldInput.tableName) {
searchField.metadata['tableName'] = fieldInput.tableName;
}
Expand All @@ -845,7 +842,7 @@ export class StudyCore {
searchField.comments = fieldInput.comments;
}

const { error } = await this.validateAndGenerateFieldEntry(searchField, requester);
const { error } = await this.validateAndGenerateFieldEntry({ ...this.fieldTypeConverter([searchField])[0], dataType: fieldInput.dataType }, requester);
if (error.length !== 0) {
throw new GraphQLError(JSON.stringify(error), { extensions: { code: errorCodes.CLIENT_MALFORMED_INPUT } });
}
Expand Down
1 change: 0 additions & 1 deletion packages/itmat-cores/src/trpcCore/fileCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ export class TRPCFileCore {
);
}
}

let fileConfig: ISystemConfig | IStudyConfig | IUserConfig | IDocConfig | ICacheConfig | IDomainConfig | null = null;
let userRepoRemainingSpace = 0;
let fileSizeLimit: number;
Expand Down
2 changes: 1 addition & 1 deletion packages/itmat-cores/src/utils/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export function standardize(study: IStudy, fields: IField[], data: IGroupedData,
}
for (const subjectId of Object.keys(data)) {
for (const visitId of Object.keys(data[subjectId])) {
if (data[subjectId][visitId][field.fieldId] === null) {
if (data[subjectId][visitId][field.fieldId] === null || data[subjectId][visitId][field.fieldId] === undefined) {
continue;
}
const dataClip: Record<string, unknown> = {};
Expand Down
4 changes: 2 additions & 2 deletions packages/itmat-docker/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@itmat-broker/itmat-setup",
"version": "2.5.1",
"version": "2.6.0",
"description": "ITMAT Broker",
"keywords": [
"itmat",
Expand All @@ -17,7 +17,7 @@
"dependencies": {
"bcrypt": "5.1.1",
"compression": "1.7.4",
"express": "4.18.2",
"express": "4.19.2",
"express-rate-limit": "7.1.2",
"isobject": "4.0.0",
"minio": "7.1.3",
Expand Down
2 changes: 0 additions & 2 deletions packages/itmat-interface/test/GraphQLTests/file.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -497,8 +497,6 @@ if (global.hasMinio) {
createdFile = res.body.data.uploadFile;
if (!createdFile)
throw 'Test file could not be retreived.';


});

afterEach(async () => {
Expand Down
16 changes: 12 additions & 4 deletions packages/itmat-interface/test/trpcTests/user.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ import { IOrganisation, enumUserTypes } from '@itmat-broker/itmat-types';
import { encodeQueryParams } from './helper';
import { errorCodes } from '@itmat-broker/itmat-cores';

jest.mock('nodemailer', () => {
const { TEST_SMTP_CRED, TEST_SMTP_USERNAME } = process.env;
if (!TEST_SMTP_CRED || !TEST_SMTP_USERNAME || !config?.nodemailer?.auth?.pass || !config?.nodemailer?.auth?.user)
return {
createTransport: jest.fn().mockImplementation(() => ({
sendMail: jest.fn()
}))
};
return jest.requireActual('nodemailer');
});

if (global.hasMinio) {
let app: Express;
let mongodb: MongoMemoryServer;
Expand Down Expand Up @@ -104,9 +115,6 @@ if (global.hasMinio) {

describe('tRPC User APIs', () => {
test('Create a user', async () => {
if (process.env.SKIP_EMAIL_TEST) {
return;
}
const response = await admin.post('/trpc/user.createUser')
.send({
username: 'test',
Expand All @@ -121,7 +129,7 @@ if (global.hasMinio) {
expect(response.body.result.data.username).toBe('test');
const user = await db.collections.users_collection.findOne({ username: 'test' });
expect(user).toBeDefined();
expect(userProfile.id).toBe(response.body.result.data.id);
expect(user.id).toBe(response.body.result.data.id);
});
test('Create a user (invalid email format)', async () => {
const response = await admin.post('/trpc/user.createUser')
Expand Down
2 changes: 1 addition & 1 deletion packages/itmat-types/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import * as Config from './config';
import * as ZodSchema from './zod';
import * as Utils from './utils';
import * as Drive from './drive';
import * as Permission from './permission';
import * as Permission from './permission';

export * from './field';
export * from './file';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ const EditableCell: FunctionComponent<EditableCellProps> = ({
})
]}
>
<RangePicker id={`period_${record.uuid}`} allowClear={false} ref={rangeRef} defaultValue={[record.startDate ?? null, record.endDate ?? null]} disabledDate={(currentDate) => {
<RangePicker id={`period_${record.uuid}`} allowClear={false} ref={rangeRef} defaultValue={[record.startDate ? dayjs(record.startDate) : null, record.endDate ?? null]} disabledDate={(currentDate) => {
return dayjs().isBefore(currentDate);
}} onCalendarChange={(dates) => {
if (dates === null)
Expand Down
Loading

0 comments on commit 3294027

Please sign in to comment.