@sjcrh/proteinpaint-server 2.138.3-0 → 2.138.3-2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import termdbTestInit from "./termdb.test.ts";
1
+ import termdbTestInit from "./termdb.test.js";
2
2
  function protected_test_default() {
3
3
  const ds = termdbTestInit();
4
4
  if (!ds.cohort)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sjcrh/proteinpaint-server",
3
- "version": "2.138.3-0",
3
+ "version": "2.138.3-2",
4
4
  "type": "module",
5
5
  "description": "a genomics visualization tool for exploring a cohort's genotype and phenotype data",
6
6
  "main": "src/app.js",
@@ -64,7 +64,7 @@
64
64
  "@sjcrh/proteinpaint-r": "2.137.2-0",
65
65
  "@sjcrh/proteinpaint-rust": "2.137.2-0",
66
66
  "@sjcrh/proteinpaint-shared": "2.137.3",
67
- "@sjcrh/proteinpaint-types": "2.138.3-0",
67
+ "@sjcrh/proteinpaint-types": "2.138.3-2",
68
68
  "@types/express": "^5.0.0",
69
69
  "@types/express-session": "^1.18.1",
70
70
  "better-sqlite3": "^9.4.1",
@@ -0,0 +1,77 @@
1
+ import { aiProjectAdminPayload } from "#types/checkers";
2
+ import { connect_db } from "../src/utils.js";
3
+ const routePath = "aiProjectAdmin";
4
+ const api = {
5
+ endpoint: `${routePath}`,
6
+ methods: {
7
+ post: {
8
+ //edit
9
+ ...aiProjectAdminPayload,
10
+ init
11
+ },
12
+ delete: {
13
+ //delete
14
+ ...aiProjectAdminPayload,
15
+ init
16
+ },
17
+ put: {
18
+ //add
19
+ ...aiProjectAdminPayload,
20
+ init
21
+ }
22
+ }
23
+ };
24
+ function init({ genomes }) {
25
+ return async (req, res) => {
26
+ try {
27
+ const query = req.query;
28
+ const g = genomes[query.genome];
29
+ const ds = g.datasets[query.dslabel];
30
+ if (!ds.queries?.WSImages?.db)
31
+ return;
32
+ const db = ds.queries.WSImages.db;
33
+ db.connection = connect_db(db.file, { readonly: false, fileMustExist: true });
34
+ if (req.method === "POST")
35
+ editProject();
36
+ if (req.method === "DELETE")
37
+ deleteProject(db.connection, query);
38
+ if (req.method === "PUT")
39
+ addProject(db.connection, query);
40
+ res.status(200).send({
41
+ status: "ok",
42
+ message: `Project ${query.projectName} processed successfully`
43
+ });
44
+ } catch (e) {
45
+ console.warn(e);
46
+ res.status(500).send({
47
+ status: "error",
48
+ error: e.message || e
49
+ });
50
+ }
51
+ };
52
+ }
53
+ function editProject() {
54
+ console.log(58, "called editProject");
55
+ }
56
+ function deleteProject(connection, query) {
57
+ const sql = `DELETE FROM Project WHERE id= ?`;
58
+ const params = [query.project.id];
59
+ runSQL(connection, sql, params, "delete");
60
+ }
61
+ function addProject(connection, query) {
62
+ const sql = `INSERT INTO Project (name) VALUES (?)`;
63
+ const params = [query.project.name];
64
+ runSQL(connection, sql, params, "add");
65
+ }
66
+ function runSQL(connection, sql, params = [], errorText = "fetch") {
67
+ try {
68
+ const rows = connection.prepare(sql).run(params);
69
+ return rows;
70
+ } catch (e) {
71
+ console.error(`Error executing SQL for ${errorText}:`, e);
72
+ throw new Error(`Failed to ${errorText} projects`);
73
+ }
74
+ }
75
+ export {
76
+ api
77
+ };
@@ -0,0 +1,50 @@
1
+ import { aiProjectListPayload } from "#types/checkers";
2
+ import { connect_db } from "../src/utils.js";
3
+ const routePath = "aiProjectList";
4
+ const api = {
5
+ endpoint: `${routePath}`,
6
+ methods: {
7
+ get: {
8
+ ...aiProjectListPayload,
9
+ init
10
+ },
11
+ post: {
12
+ ...aiProjectListPayload,
13
+ init
14
+ }
15
+ }
16
+ };
17
+ function init({ genomes }) {
18
+ return async (req, res) => {
19
+ try {
20
+ const query = req.query;
21
+ const g = genomes[query.genome];
22
+ const ds = g.datasets[query.dslabel];
23
+ const projects = getProjects(ds);
24
+ res.send(projects);
25
+ } catch (e) {
26
+ console.warn(e);
27
+ res.status(500).send({
28
+ status: "error",
29
+ error: e.message || e
30
+ });
31
+ }
32
+ };
33
+ }
34
+ function getProjects(ds) {
35
+ if (!ds.queries?.WSImages?.db)
36
+ return;
37
+ const db = ds.queries.WSImages.db;
38
+ const sql = "SELECT project.name as value, id FROM Project";
39
+ try {
40
+ db.connection = connect_db(db.file, { readonly: false, fileMustExist: true });
41
+ const rows = db.connection.prepare(sql).all();
42
+ return rows;
43
+ } catch (e) {
44
+ console.error("Error fetching projects:", e);
45
+ throw new Error("Failed to fetch projects");
46
+ }
47
+ }
48
+ export {
49
+ api
50
+ };