@opengis/fastify-table 1.1.29 → 1.1.30
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.
- package/Changelog.md +4 -0
- package/index.js +3 -23
- package/notification/index.js +1 -33
- package/package.json +1 -1
- package/server/migrations/crm.sql +0 -23
- package/test/api/notification.test.js +0 -26
package/Changelog.md
CHANGED
package/index.js
CHANGED
|
@@ -49,29 +49,9 @@ async function plugin(fastify, opt) {
|
|
|
49
49
|
return filepath;
|
|
50
50
|
});
|
|
51
51
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const clsDir = path.join(process.cwd(), 'server/templates/cls');
|
|
56
|
-
const files = existsSync(clsDir) ? readdirSync(clsDir) : [];
|
|
57
|
-
if (files.length) {
|
|
58
|
-
const res = await Promise.all(files.map(async (filename) => {
|
|
59
|
-
const filepath = path.join(clsDir, filename);
|
|
60
|
-
const data = JSON.parse(readFileSync(filepath));
|
|
61
|
-
return { name: path.parse(filename).name, data };
|
|
62
|
-
}));
|
|
63
|
-
await client.query('truncate table crm.cls');
|
|
64
|
-
const { rows } = await client.query(`insert into crm.cls(name, type)
|
|
65
|
-
select value->>'name', 'json' from json_array_elements($1) returning cls_id as id, name`, [JSON.stringify(res).replace(/'/g, "''")]);
|
|
66
|
-
rows.forEach((row) => Object.assign(row, { data: res.find((cls) => row.name === cls.name)?.data }));
|
|
67
|
-
const sql = `insert into crm.cls(code, name, parent)
|
|
68
|
-
select json_array_elements(value->'data')->>'id', json_array_elements(value->'data')->>'text', value->>'name' from json_array_elements($1)`;
|
|
69
|
-
await client.query(sql, [JSON.stringify(rows).replace(/'/g, "''")]);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
// execute core migrations
|
|
73
|
-
await execMigrations();
|
|
74
|
-
});
|
|
52
|
+
// core migrations
|
|
53
|
+
await execMigrations();
|
|
54
|
+
|
|
75
55
|
if (!fastify.funcs) {
|
|
76
56
|
fastify.addHook('onRequest', async (req) => {
|
|
77
57
|
req.funcs = fastify;
|
package/notification/index.js
CHANGED
|
@@ -1,43 +1,12 @@
|
|
|
1
1
|
// api
|
|
2
|
-
import readNotifications from './controllers/readNotifications.js'; // mark as read
|
|
3
|
-
import userNotifications from './controllers/userNotifications.js'; // check all, backend pagination
|
|
4
2
|
import testEmail from './controllers/testEmail.js';
|
|
5
3
|
// funcs
|
|
6
4
|
import addNotification from './funcs/addNotification.js'; // add to db
|
|
7
5
|
import notification from './funcs/sendNotification.js'; // send notification
|
|
8
6
|
|
|
9
|
-
import onWidgetSet from './hook/onWidgetSet.js'; // send notification on comment
|
|
10
|
-
import { addHook } from '../utils.js';
|
|
11
|
-
|
|
12
|
-
const tableSchema = {
|
|
13
|
-
params: {
|
|
14
|
-
id: { type: 'string' },
|
|
15
|
-
},
|
|
16
|
-
querystring: {
|
|
17
|
-
nocache: { type: 'string', pattern: '^(\\d+)$' },
|
|
18
|
-
},
|
|
19
|
-
};
|
|
20
|
-
|
|
21
7
|
async function plugin(fastify, config = {}) {
|
|
22
8
|
const prefix = config.prefix || '/api';
|
|
23
|
-
|
|
24
|
-
method: 'GET',
|
|
25
|
-
url: `${prefix}/notification`,
|
|
26
|
-
config: {
|
|
27
|
-
policy: ['user'],
|
|
28
|
-
},
|
|
29
|
-
schema: tableSchema,
|
|
30
|
-
handler: userNotifications,
|
|
31
|
-
});
|
|
32
|
-
fastify.route({
|
|
33
|
-
method: 'GET',
|
|
34
|
-
url: `${prefix}/notification-read/:id?`,
|
|
35
|
-
config: {
|
|
36
|
-
policy: ['user'],
|
|
37
|
-
},
|
|
38
|
-
schema: tableSchema,
|
|
39
|
-
handler: readNotifications,
|
|
40
|
-
});
|
|
9
|
+
|
|
41
10
|
fastify.route({
|
|
42
11
|
method: 'GET',
|
|
43
12
|
url: `${prefix}/test-email`,
|
|
@@ -49,7 +18,6 @@ async function plugin(fastify, config = {}) {
|
|
|
49
18
|
|
|
50
19
|
fastify.decorate('addNotification', addNotification);
|
|
51
20
|
fastify.decorate('notification', notification);
|
|
52
|
-
addHook('onWidgetSet', onWidgetSet);
|
|
53
21
|
}
|
|
54
22
|
|
|
55
23
|
export default plugin;
|
package/package.json
CHANGED
|
@@ -113,29 +113,6 @@ ALTER TABLE crm.checklists ADD COLUMN IF NOT EXISTS editor_id text;
|
|
|
113
113
|
ALTER TABLE crm.checklists ADD COLUMN IF NOT EXISTS editor_date timestamp without time zone;
|
|
114
114
|
ALTER TABLE crm.checklists ADD CONSTRAINT crm_checklists_pkey PRIMARY KEY (checklist_id);
|
|
115
115
|
|
|
116
|
-
-- crm.cls
|
|
117
|
-
-- DROP TABLE IF EXISTS crm.cls;
|
|
118
|
-
CREATE TABLE IF NOT EXISTS crm.cls();
|
|
119
|
-
ALTER TABLE crm.cls DROP CONSTRAINT IF EXISTS crm_cls_pkey;
|
|
120
|
-
ALTER TABLE crm.cls DROP CONSTRAINT IF EXISTS crm_cls_unique;
|
|
121
|
-
ALTER TABLE crm.cls ADD COLUMN IF NOT EXISTS cls_id text NOT NULL DEFAULT next_id();
|
|
122
|
-
|
|
123
|
-
ALTER TABLE crm.cls ADD COLUMN IF NOT EXISTS name text;
|
|
124
|
-
ALTER TABLE crm.cls ADD COLUMN IF NOT EXISTS data text;
|
|
125
|
-
ALTER TABLE crm.cls ADD COLUMN IF NOT EXISTS type text;
|
|
126
|
-
ALTER TABLE crm.cls ADD COLUMN IF NOT EXISTS parent text;
|
|
127
|
-
ALTER TABLE crm.cls ADD COLUMN IF NOT EXISTS code text;
|
|
128
|
-
ALTER TABLE crm.cls ADD COLUMN IF NOT EXISTS color text;
|
|
129
|
-
ALTER TABLE crm.cls ADD COLUMN IF NOT EXISTS icon text;
|
|
130
|
-
|
|
131
|
-
ALTER TABLE crm.cls ADD COLUMN IF NOT EXISTS uid text;
|
|
132
|
-
ALTER TABLE crm.cls ADD COLUMN IF NOT EXISTS files json;
|
|
133
|
-
ALTER TABLE crm.cls ADD COLUMN IF NOT EXISTS cdate timestamp without time zone DEFAULT (now())::timestamp without time zone;
|
|
134
|
-
ALTER TABLE crm.cls ADD COLUMN IF NOT EXISTS editor_id text;
|
|
135
|
-
ALTER TABLE crm.cls ADD COLUMN IF NOT EXISTS editor_date timestamp without time zone;
|
|
136
|
-
ALTER TABLE crm.cls ADD CONSTRAINT crm_cls_pkey PRIMARY KEY (cls_id);
|
|
137
|
-
ALTER TABLE crm.cls ADD CONSTRAINT crm_cls_unique UNIQUE (code, parent);
|
|
138
|
-
|
|
139
116
|
-- DROP TABLE crm.properties;
|
|
140
117
|
CREATE TABLE IF NOT EXISTS crm.properties();
|
|
141
118
|
ALTER TABLE crm.properties DROP CONSTRAINT IF EXISTS crm_properties_pkey;
|
|
@@ -25,32 +25,6 @@ test('api && funcs notification', async (t) => {
|
|
|
25
25
|
if (!notificationIds?.length) {
|
|
26
26
|
assert.ok(0, 'insert notification error');
|
|
27
27
|
}
|
|
28
|
-
await t.test('GET /notification', async () => {
|
|
29
|
-
const res = await app.inject({
|
|
30
|
-
method: 'GET',
|
|
31
|
-
url: '/api/notification',
|
|
32
|
-
});
|
|
33
|
-
const rep = res.json();
|
|
34
|
-
assert.ok(rep.total > 0);
|
|
35
|
-
});
|
|
36
|
-
await t.test('GET /notification-read/:id', async () => {
|
|
37
|
-
const res = await app.inject({
|
|
38
|
-
method: 'GET',
|
|
39
|
-
url: `/api/notification-read/${notificationIds[0]}`,
|
|
40
|
-
});
|
|
41
|
-
const rep = res.json();
|
|
42
|
-
assert.ok(!rep.message?.startsWith(0), res.body);
|
|
43
|
-
assert.ok(rep.message?.includes('unread notifications marked'), res.body);
|
|
44
|
-
});
|
|
45
|
-
await t.test('GET /notification-read', async () => {
|
|
46
|
-
const res = await app.inject({
|
|
47
|
-
method: 'GET',
|
|
48
|
-
url: '/api/notification-read',
|
|
49
|
-
});
|
|
50
|
-
const rep = res.json();
|
|
51
|
-
assert.ok(!rep.message?.startsWith(0), res.body);
|
|
52
|
-
assert.ok(rep.message?.includes('unread notifications marked'), res.body);
|
|
53
|
-
});
|
|
54
28
|
|
|
55
29
|
const { sql } = await getSelect('core.user_mentioned');
|
|
56
30
|
const { name } = await pg.query(`with data (id,name,email) as (${sql})
|