mirror of https://github.com/msgbyte/tailchat
feat: create discover plugin and define db schema
parent
99c8779ffd
commit
4cd2267d64
@ -1 +1,4 @@
|
|||||||
console.log('Plugin {{name}} is loaded');
|
const PLUGIN_ID = '{{id}}';
|
||||||
|
const PLUGIN_NAME = '{{name}}';
|
||||||
|
|
||||||
|
console.log(`Plugin ${PLUGIN_NAME}(${PLUGIN_ID}) is loaded`);
|
||||||
|
@ -0,0 +1,14 @@
|
|||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
externalDeps: [
|
||||||
|
'react',
|
||||||
|
'react-router',
|
||||||
|
'axios',
|
||||||
|
'styled-components',
|
||||||
|
'zustand',
|
||||||
|
'zustand/middleware/immer',
|
||||||
|
],
|
||||||
|
pluginRoot: path.resolve(__dirname, './web'),
|
||||||
|
outDir: path.resolve(__dirname, '../../public'),
|
||||||
|
};
|
@ -0,0 +1,30 @@
|
|||||||
|
import { db } from 'tailchat-server-sdk';
|
||||||
|
import { Group } from '../../../models/group/group';
|
||||||
|
const { getModelForClass, prop, modelOptions, TimeStamps } = db;
|
||||||
|
|
||||||
|
@modelOptions({
|
||||||
|
options: {
|
||||||
|
customName: 'p_discover',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
export class Discover extends TimeStamps implements db.Base {
|
||||||
|
_id: db.Types.ObjectId;
|
||||||
|
id: string;
|
||||||
|
|
||||||
|
@prop({ ref: () => Group })
|
||||||
|
groupId: db.Ref<Group>;
|
||||||
|
|
||||||
|
@prop({ default: true })
|
||||||
|
active: boolean;
|
||||||
|
|
||||||
|
@prop({ default: 0 })
|
||||||
|
order: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type DiscoverDocument = db.DocumentType<Discover>;
|
||||||
|
|
||||||
|
const model = getModelForClass(Discover);
|
||||||
|
|
||||||
|
export type DiscoverModel = typeof model;
|
||||||
|
|
||||||
|
export default model;
|
@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"name": "tailchat-plugin-discover",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"main": "index.js",
|
||||||
|
"author": "moonrailgun",
|
||||||
|
"description": "Add Discover panel which can help user found groups",
|
||||||
|
"license": "MIT",
|
||||||
|
"private": true,
|
||||||
|
"scripts": {
|
||||||
|
"build:web": "ministar buildPlugin all",
|
||||||
|
"build:web:watch": "ministar watchPlugin all"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/react": "18.0.20",
|
||||||
|
"mini-star": "*"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"tailchat-server-sdk": "*"
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,45 @@
|
|||||||
|
import type { TcContext } from 'tailchat-server-sdk';
|
||||||
|
import { TcService, TcDbService } from 'tailchat-server-sdk';
|
||||||
|
import type { DiscoverDocument, DiscoverModel } from '../models/discover';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Discover
|
||||||
|
*
|
||||||
|
* Add Discover panel which can help user found groups
|
||||||
|
*/
|
||||||
|
interface DiscoverService
|
||||||
|
extends TcService,
|
||||||
|
TcDbService<DiscoverDocument, DiscoverModel> {}
|
||||||
|
class DiscoverService extends TcService {
|
||||||
|
get serviceName() {
|
||||||
|
return 'plugin:com.msgbyte.discover';
|
||||||
|
}
|
||||||
|
|
||||||
|
onInit() {
|
||||||
|
this.registerLocalDb(require('../models/discover').default);
|
||||||
|
|
||||||
|
this.registerAction('all', this.all, {
|
||||||
|
params: {
|
||||||
|
page: { type: 'number', default: 1 },
|
||||||
|
size: { type: 'number', default: 20 },
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async all(ctx: TcContext<{ page: number; size: number }>) {
|
||||||
|
const { page, size } = ctx.params;
|
||||||
|
|
||||||
|
const docs = await this.adapter.model
|
||||||
|
.find({
|
||||||
|
active: true,
|
||||||
|
})
|
||||||
|
.limit(size)
|
||||||
|
.skip(size * (page - 1));
|
||||||
|
|
||||||
|
const list = await this.transformDocuments(ctx, {}, docs);
|
||||||
|
|
||||||
|
return { list };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default DiscoverService;
|
@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"label": "Discover",
|
||||||
|
"name": "com.msgbyte.discover",
|
||||||
|
"url": "{BACKEND}/plugins/com.msgbyte.discover/index.js",
|
||||||
|
"version": "0.0.0",
|
||||||
|
"author": "moonrailgun",
|
||||||
|
"description": "Add Discover panel which can help user found groups",
|
||||||
|
"requireRestart": true
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"name": "@plugins/com.msgbyte.discover",
|
||||||
|
"main": "src/index.tsx",
|
||||||
|
"version": "0.0.0",
|
||||||
|
"description": "Add Discover panel which can help user found groups",
|
||||||
|
"private": true,
|
||||||
|
"scripts": {
|
||||||
|
"sync:declaration": "tailchat declaration github"
|
||||||
|
},
|
||||||
|
"dependencies": {},
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/styled-components": "^5.1.26",
|
||||||
|
"react": "18.2.0",
|
||||||
|
"styled-components": "^5.3.6"
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1 @@
|
|||||||
|
console.log('Plugin Discover is loaded');
|
@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"jsx": "react",
|
||||||
|
"importsNotUsedAsValues": "error"
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,2 @@
|
|||||||
|
declare module '@capital/common';
|
||||||
|
declare module '@capital/component';
|
Loading…
Reference in New Issue