Skip to content

Commit

Permalink
lint fixes and tidying up
Browse files Browse the repository at this point in the history
Signed-off-by: Steve Cassidy <[email protected]>
  • Loading branch information
stevecassidy committed Aug 24, 2023
1 parent 9086abf commit be03d14
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 39 deletions.
6 changes: 4 additions & 2 deletions src/api/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,8 @@ api.post('/users/:id/admin', requireAuthenticationAPI, async (req, res) => {
});

if (DEVELOPER_MODE) {
api.post('/notebooks/:notebook_id/delete',
api.post(
'/notebooks/:notebook_id/delete',
requireAuthenticationAPI,
async (req, res) => {
if (userIsClusterAdmin(req.user)) {
Expand All @@ -253,7 +254,8 @@ if (DEVELOPER_MODE) {
}
);

api.post('/notebooks/:notebook_id/generate',
api.post(
'/notebooks/:notebook_id/generate',
requireAuthenticationAPI,
async (req, res) => {
if (userIsClusterAdmin(req.user)) {
Expand Down
6 changes: 5 additions & 1 deletion src/buildconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,11 @@ function email_transporter(): any {

function developer_mode(): any {
const develop = process.env.DEVELOPER_MODE;
return develop === 'true';
if (develop) {
return TRUTHY_STRINGS.includes(develop?.toLowerCase());
} else {
return false;
}
}

export const DEVELOPER_MODE = developer_mode();
Expand Down
2 changes: 1 addition & 1 deletion src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* which server to use and whether to include test data
*/

import express from 'express';
import express from 'express';
import cookieSession from 'cookie-session';
import cors from 'cors';
import passport from 'passport';
Expand Down
15 changes: 8 additions & 7 deletions src/couchdb/devtools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@
* Tools used in development and testing of FAIMS
*/

import {ProjectID, upsertFAIMSData, Record, generateFAIMSDataID} from 'faims3-datamodel';
import {
ProjectID,
upsertFAIMSData,
Record,
generateFAIMSDataID,
} from 'faims3-datamodel';
import {getNotebookUISpec} from './notebooks';
import {randomInt} from 'crypto';
import { readFileSync } from 'node:fs';
import { readFile } from 'fs';
import { Blob } from 'buffer';

import {readFileSync} from 'node:fs';

export const createManyRandomRecords = async (
project_id: ProjectID,
Expand Down Expand Up @@ -72,7 +74,7 @@ export const createRandomRecord = async (project_id: ProjectID) => {
});
const values: {[key: string]: any} = {
fieldNames: [],
views: []
views: [],
};
fields.map((field: string) => {
values[field] = generateValue(uiSpec.fields[field]);
Expand Down Expand Up @@ -103,7 +105,6 @@ export const createRandomRecord = async (project_id: ProjectID) => {
}
};


const SAMPLE_IMAGE_FILE = 'public/images/Faims-medium.png';

const generateValue = (field: any) => {
Expand Down
2 changes: 1 addition & 1 deletion src/couchdb/invites.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export async function createInvite(
project_id: project_id,
role: role,
number: number,
unlimited: number == 0,
unlimited: number === 0,
};
await saveInvite(invite);
return invite;
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ registerClient({
});

process.on('unhandledRejection', error => {
console.error('unhandledRejection');
console.error('unhandledRejection');
console.error(error); // This prints error with stack included (as for normal errors)
// don't re-throw the error since we don't want to crash the server
});
Expand Down
1 change: 1 addition & 0 deletions src/registration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,5 @@ export async function acceptInvite(user: Express.User, invite: RoleInvite) {

export async function rejectInvite(invite: RoleInvite) {
//await deleteInvite(invite);
console.log('rejecting', invite);
}
4 changes: 2 additions & 2 deletions src/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ app.post(
}
const project_id: NonUniqueProjectID = req.params.id;
const role: string = req.body.role;
const number: number = req.body.number;
const number: number = req.body.number.parseInt();

if (!userHasPermission(req.user, project_id, 'modify')) {
res.render('invite-error', {
Expand Down Expand Up @@ -145,7 +145,7 @@ app.get(
notebook: notebook,
records: await countRecordsInNotebook(project_id),
invites: invitesQR,
developer: DEVELOPER_MODE
developer: DEVELOPER_MODE,
});
} else {
res.sendStatus(404);
Expand Down
2 changes: 0 additions & 2 deletions test/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ const uispec: ProjectUIModel = {

let adminToken = '';
const username = 'bobalooba';
let bobalooba: Express.User;

beforeAll(async () => {
await initialiseDatabases();
Expand All @@ -57,7 +56,6 @@ beforeAll(async () => {
const [user, error] = await createUser('', username);
if (user) {
await saveUser(user);
bobalooba = user;
} else {
throw new Error(error);
}
Expand Down
22 changes: 0 additions & 22 deletions test/devtools.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ PouchDB.plugin(require('pouchdb-find'));
import {
getProjectDataDB,
getProjectMetaDB,
getProjectsDB,
getUsersDB,
initialiseDatabases,
} from '../src/couchdb';
import {createNotebook} from '../src/couchdb/notebooks';
Expand All @@ -40,26 +38,6 @@ registerClient({
shouldDisplayRecord: () => true,
});

const clearDB = async (db: PouchDB.Database) => {
const docs = await db.allDocs();
for (let index = 0; index < docs.rows.length; index++) {
const doc = docs.rows[index];
await db.remove(doc.id, doc.value.rev);
}
};

const resetDatabases = async () => {
const usersDB = getUsersDB();
if (usersDB) {
await clearDB(usersDB);
}
const projectsDB = getProjectsDB();
if (projectsDB) {
await clearDB(projectsDB);
}
await initialiseDatabases();
};

test('createRecords', async () => {
await initialiseDatabases();

Expand Down

0 comments on commit be03d14

Please sign in to comment.