@kne/fastify-message 1.0.5 → 1.0.6
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/index.js +22 -43
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,54 +1,33 @@
|
|
|
1
1
|
const fp = require('fastify-plugin');
|
|
2
2
|
const path = require('node:path');
|
|
3
3
|
|
|
4
|
-
module.exports = fp(async function
|
|
5
|
-
options = Object.assign(
|
|
6
|
-
{
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
dbTableNamePrefix: 't_message_',
|
|
10
|
-
prefix: '/api/v1/message',
|
|
11
|
-
getUserModel: () => {
|
|
12
|
-
if (!fastify.account) {
|
|
13
|
-
throw new Error('fastify-account plugin must be registered before fastify-trtc-conference,or set options.getUserModel');
|
|
14
|
-
}
|
|
15
|
-
return fastify.account.models.user;
|
|
16
|
-
},
|
|
17
|
-
senders: {},
|
|
18
|
-
getAuthenticate: (type) => {
|
|
19
|
-
switch (type) {
|
|
20
|
-
case 'record':
|
|
21
|
-
case 'template':
|
|
22
|
-
default:
|
|
23
|
-
return [];
|
|
24
|
-
}
|
|
4
|
+
module.exports = fp(async function(fastify, options) {
|
|
5
|
+
options = Object.assign({}, {
|
|
6
|
+
name: 'message', dbTableNamePrefix: 't_message_', prefix: '/api/v1/message', getUserModel: () => {
|
|
7
|
+
if (!fastify.account) {
|
|
8
|
+
throw new Error('fastify-account plugin must be registered before fastify-message,or set options.getUserModel');
|
|
25
9
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
10
|
+
return fastify.account.models.user;
|
|
11
|
+
}, senders: {}, getAuthenticate: (type) => {
|
|
12
|
+
if (!fastify.account) {
|
|
13
|
+
throw new Error('fastify-account plugin must be registered before fastify-message,or set options.getAuthenticate');
|
|
14
|
+
}
|
|
15
|
+
const { authenticate } = fastify.account;
|
|
16
|
+
return [authenticate.user, authenticate.admin];
|
|
17
|
+
}
|
|
18
|
+
}, options);
|
|
29
19
|
|
|
30
20
|
fastify.register(require('@kne/fastify-namespace'), {
|
|
31
21
|
name: options.name,
|
|
32
22
|
options,
|
|
33
|
-
modules: [
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
await fastify.sequelize.addModels(path.resolve(__dirname, './libs/models'), {
|
|
37
|
-
prefix: options.dbTableNamePrefix,
|
|
38
|
-
getUserModel: options.getUserModel
|
|
39
|
-
})
|
|
40
|
-
],
|
|
41
|
-
['services', path.resolve(__dirname, './libs/services')],
|
|
42
|
-
['controllers', path.resolve(__dirname, './libs/controllers')]
|
|
43
|
-
]
|
|
23
|
+
modules: [['models', await fastify.sequelize.addModels(path.resolve(__dirname, './libs/models'), {
|
|
24
|
+
prefix: options.dbTableNamePrefix, getUserModel: options.getUserModel
|
|
25
|
+
})], ['services', path.resolve(__dirname, './libs/services')], ['controllers', path.resolve(__dirname, './libs/controllers')]]
|
|
44
26
|
});
|
|
45
27
|
|
|
46
|
-
fastify.register(
|
|
47
|
-
|
|
48
|
-
fastify.
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}),
|
|
52
|
-
options
|
|
53
|
-
);
|
|
28
|
+
fastify.register(fp((fastify, options) => {
|
|
29
|
+
fastify.sequelize.syncPromise.then(() => {
|
|
30
|
+
return fastify[options.name].services.includeTemplate(options.templateDir);
|
|
31
|
+
});
|
|
32
|
+
}), options);
|
|
54
33
|
});
|