Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed SonarCloud issues #66

Merged
merged 3 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
42 changes: 21 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,52 +10,52 @@
"types": "dist/index.d.ts",
"devDependencies": {
"@machinomy/types-node-db-migrate": "^0.0.2",
"@types/bcryptjs": "^2.4.2",
"@types/compression": "^1.7.2",
"@types/connect-pg-simple": "^7.0.0",
"@types/bcryptjs": "^2.4.4",
"@types/compression": "^1.7.3",
"@types/connect-pg-simple": "^7.0.1",
"@types/db-migrate-base": "^0.0.10",
"@types/express": "^4.17.14",
"@types/express-fileupload": "^1.4.1",
"@types/express-session": "^1.17.5",
"@types/jest": "^29.5.1",
"@types/jest": "^29.5.5",
"@types/lodash.throttle": "^4.1.7",
"@types/passport": "^1.0.12",
"@types/passport-local": "^1.0.35",
"@types/supertest": "^2.0.12",
"@typescript-eslint/eslint-plugin": "^5.59.1",
"@typescript-eslint/parser": "^5.59.1",
"@typescript-eslint/eslint-plugin": "^6.7.0",
"@typescript-eslint/parser": "^6.7.0",
"copyfiles": "^2.4.1",
"dotenv": "^16.0.3",
"eslint": "^8.39.0",
"dotenv": "^16.3.1",
"eslint": "^8.49.0",
"husky": "8.0.3",
"jest": "^29.5.0",
"lint-staged": "^13.2.2",
"jest": "^29.7.0",
"lint-staged": "^14.0.1",
"npm-run-all": "^4.1.5",
"prettier": "2.8.8",
"rimraf": "^5.0.0",
"prettier": "3.0.3",
"rimraf": "^5.0.1",
"supertest": "^6.3.3",
"ts-jest": "^29.1.0",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.1",
"typescript": "^5.0.4"
"typescript": "^5.2.2"
},
"dependencies": {
"@godaddy/terminus": "^4.12.0",
"@openforis/arena-core": "^0.0.136",
"@godaddy/terminus": "^4.12.1",
"@openforis/arena-core": "^0.0.164",
"bcryptjs": "^2.4.3",
"body-parser": "^1.20.2",
"compression": "^1.7.4",
"connect-pg-simple": "^8.0.0",
"db-migrate": "^0.11.13",
"db-migrate-pg": "^1.2.2",
"connect-pg-simple": "^9.0.0",
"db-migrate": "^0.11.14",
"db-migrate-pg": "^1.5.2",
"express": "^4.18.2",
"express-fileupload": "^1.4.0",
"express-session": "^1.17.2",
"lodash.throttle": "^4.1.1",
"log4js": "^6.9.1",
"passport": "^0.6.0",
"passport-local": "^1.0.0",
"pg-promise": "^11.4.3",
"socket.io": "^4.6.1"
"pg-promise": "^11.5.4",
"socket.io": "^4.7.2"
},
"scripts": {
"build": "run-s tsc copy-assets",
Expand Down
2 changes: 1 addition & 1 deletion src/api/tests/mock/user.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { User, UserFactory } from '@openforis/arena-core'

export const mockUser: User = {
...UserFactory.createInstance({ email: 'test@arena.com', name: 'Tester' }),
...UserFactory.createInstance({ email: 'test@openforis-arena.org', name: 'Tester' }),
password: 'test',
}

Expand Down
2 changes: 1 addition & 1 deletion src/api/tests/utils/insertTestUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const insertTestUser = async (): Promise<void> =>
g.uuid
FROM
"user" u
JOIN auth_group g ON u.email = 'test@arena.com'
JOIN auth_group g ON u.email = 'test@openforis-arena.org'
AND g.name = 'systemAdmin'`
)
})
9 changes: 5 additions & 4 deletions src/db/sql/sqlUpdateBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ export class SqlUpdateBuilder extends SqlBuilder {
if (Objects.isEmpty(this._update) || Objects.isEmpty(this._set))
throw new Error(`missingParams, ${this._update}, ${this._set}`)
const _getColumnName = (column: Column | string) => (typeof column === 'string' ? column : column.columnName)
const parts: Array<string> = [
`UPDATE ${this._update}`,
`SET ${this._set.map(({ column, value }: SetType) => `${_getColumnName(column)} = ${value}`).join(', ')}`,
]
const _buildSetValue = (params: SetType): string => {
const { column, value } = params
return `${_getColumnName(column)} = ${value}`
}
const parts: Array<string> = [`UPDATE ${this._update}`, `SET ${this._set.map(_buildSetValue).join(', ')}`]

if (!Objects.isEmpty(this._where)) {
parts.push(`WHERE ${this._where.join(' ')}`)
Expand Down
4 changes: 2 additions & 2 deletions src/job/job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export abstract class JobServer<C extends JobContext = JobContext, R = undefined
} catch (error: any) {
if (this.summary.status === JobStatus.running) {
// Error found, change status only if not changed already
this.logger.error(error.stack || error)
this.logger.error(error.stack ?? error)
this.addError({
error: {
valid: false,
Expand Down Expand Up @@ -194,7 +194,7 @@ export abstract class JobServer<C extends JobContext = JobContext, R = undefined

protected addError(error: any, errorKey?: string): void {
if (!this.summary.errors) this.summary.errors = {}
const key = errorKey || String(this.summary.processed + 1)
const key = errorKey ?? String(this.summary.processed + 1)
this.summary.errors[key] = error
}
}
2 changes: 1 addition & 1 deletion src/job/jobManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class JobManager {
worker.postMessage({ type: JobMessageInType.cancel })
}

private static async onMessage(msg: JobMessageOut): Promise<void> {
private static onMessage(msg: JobMessageOut): void {
if (msg.type === JobMessageOutType.summaryUpdate) {
const { summary } = msg
const { status, userUuid } = summary
Expand Down
6 changes: 2 additions & 4 deletions src/job/jobThread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ import { JobRegistry } from './jobRegistry'
export class JobThread<C extends JobContext> extends Thread<JobMessageIn, JobMessageOut, C> {
private job: JobServer<any, any> | undefined

constructor() {
super()

startJob() {
JobRegistry.getInstance().then((jobRegistry: JobRegistry) => {
const Job = jobRegistry.get(this.data.type)
if (!Job) throw new ServerError('jobNotRegistered', this.data)
Expand Down Expand Up @@ -41,4 +39,4 @@ export class JobThread<C extends JobContext> extends Thread<JobMessageIn, JobMes
}
}

if (!isMainThread) new JobThread()
if (!isMainThread) new JobThread().startJob()
2 changes: 1 addition & 1 deletion src/job/tests/job.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ afterAll(async () => {

describe('Job', () => {
const user = UserFactory.createInstance({
email: 'test@arena.com',
email: 'test@openforis-arena.org',
name: 'Tester',
status: UserStatus.ACCEPTED,
title: UserTitle.mr,
Expand Down
2 changes: 1 addition & 1 deletion src/job/tests/testJobs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class SimpleJob extends JobServer<SimpleJobContext, number> {

protected async prepareResult(): Promise<number> {
await super.prepareResult()
return this.context.result || 3
return this.context.result ?? 3
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/processEnv/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const dbUrl = process.env.DATABASE_URL

const regExDbUrl = /postgres:\/\/(\w+):(\w+)@([\w-.\d]+):(\d+)\/(\w+)/
const regExDbUrl = /postgres:\/\/(\w+):(\w+)@([\w.\d]+):(\d+)\/(\w+)/

const dbUrlMatch = dbUrl ? dbUrl.match(regExDbUrl) : null

Expand Down
3 changes: 1 addition & 2 deletions src/repository/survey/get.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Survey } from '@openforis/arena-core'
import { BaseProtocol, DB, SqlSelectBuilder, TableSurvey } from '../../db'
import { DBs } from '../../db'
import { BaseProtocol, DB, DBs, SqlSelectBuilder, TableSurvey } from '../../db'

/**
* Returns a survey by id.
Expand Down
6 changes: 3 additions & 3 deletions src/server/middleware/header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ const maxAgeSeconds = 60 * 60 * 24 * 365
export const HeaderMiddleware: ExpressInitializer = {
init(express: Express): void {
express.use((req, res, next) => {
if (req.path.match(apiRegexp)) {
if (apiRegexp.test(req.path)) {
res.set('Cache-Control', 'no-store')
} else if (req.path.match(bundleRegexp)) {
} else if (bundleRegexp.test(req.path)) {
res.set('Cache-Control', `public, max-age=${maxAgeSeconds}`)
// Resource-reference cache-busted with uuidv4 in the end (see webpack.config.js)
} else if (req.query.bust && (req.query.bust as string).match(bustRegexp)) {
} else if (req.query.bust && bustRegexp.test(req.query.bust as string)) {
res.set('Cache-Control', `public, max-age=${maxAgeSeconds}`)
} else {
res.set('Cache-Control', 'no-store')
Expand Down
4 changes: 1 addition & 3 deletions src/service/record/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { Record, RecordService } from '@openforis/arena-core'

import { User } from '@openforis/arena-core'
import { Record, RecordService, User } from '@openforis/arena-core'

import { get } from './get'

Expand Down
Loading
Loading