Commit 0cfce6d0 authored by huanglu's avatar huanglu

feat: 去除mongo

parent 2ad1654c
import { Application } from 'egg'; import { Application } from 'egg';
module.exports = (app: Application) => { // eslint-disable-next-line @typescript-eslint/no-unused-vars
const mongoose = app.mongoose; module.exports = (_app: Application) => {
const Schema = mongoose.Schema; // const mongoose = app.mongoose;
// const Schema = mongoose.Schema;
const ChatRoomSchema = new Schema({ // const ChatRoomSchema = new Schema({
roomId: { type: String }, // roomId: { type: String },
roomName: { type: String }, // roomName: { type: String },
ids: { type: Array }, // ids: { type: Array },
}); // });
ChatRoomSchema.pre('save', async function(next) { // ChatRoomSchema.pre('save', async function(next) {
app.model.GCounter.findByIdAndUpdate('chatRoomId', { $inc: { roomId: 1 } as any }, { new: true, upsert: true }, (error, counter) => { // app.model.GCounter.findByIdAndUpdate('chatRoomId', { $inc: { roomId: 1 } as any }, { new: true, upsert: true }, (error, counter) => {
if (error) return next(error); // if (error) return next(error);
(this as any).roomId = (counter as any).roomId; // (this as any).roomId = (counter as any).roomId;
next(); // next();
}); // });
}); // });
return mongoose.model('ChatRoom', ChatRoomSchema); // return mongoose.model('ChatRoom', ChatRoomSchema);
}; };
import { Application } from 'egg'; import { Application } from 'egg';
module.exports = (app: Application) => { // eslint-disable-next-line @typescript-eslint/no-unused-vars
const mongoose = app.mongoose; module.exports = (_app: Application) => {
const Schema = mongoose.Schema; // const mongoose = app.mongoose;
// const Schema = mongoose.Schema;
const ChatUserSchema = new Schema({ // const ChatUserSchema = new Schema({
name: { type: String }, // name: { type: String },
username: { type: String }, // username: { type: String },
avator: { type: String }, // avator: { type: String },
password: { type: String }, // password: { type: String },
token: { type: String }, // token: { type: String },
userId: { type: Number }, // userId: { type: Number },
}); // });
const userModel = mongoose.model('ChatUser', ChatUserSchema); // const userModel = mongoose.model('ChatUser', ChatUserSchema);
return userModel; // return userModel;
}; };
import { Application } from 'egg'; import { Application } from 'egg';
module.exports = (app: Application) => { // eslint-disable-next-line @typescript-eslint/no-unused-vars
const mongoose = app.mongoose; module.exports = (_app: Application) => {
const Schema = mongoose.Schema; // const mongoose = app.mongoose;
// const Schema = mongoose.Schema;
const RoomCounterSchema = new Schema({ // const RoomCounterSchema = new Schema({
_id: { type: String, default: 'chatRoomId' }, // _id: { type: String, default: 'chatRoomId' },
roomId: { type: Number }, // roomId: { type: Number },
userId: { type: Number, default: 100000 }, // userId: { type: Number, default: 100000 },
}); // });
return mongoose.model('GCounter', RoomCounterSchema); // return mongoose.model('GCounter', RoomCounterSchema);
}; };
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
}, },
"scripts": { "scripts": {
"start": "npm run tsc && egg-scripts start --daemon --sticky", "start": "npm run tsc && egg-scripts start --daemon --sticky",
"stop": "egg-scripts stop --title=egg-server-geek-egg", "stop": "egg-scripts stop",
"dev": "egg-bin dev --sticky", "dev": "egg-bin dev --sticky",
"debug": "egg-bin debug", "debug": "egg-bin debug",
"test-local": "egg-bin test", "test-local": "egg-bin test",
......
...@@ -18,7 +18,6 @@ import 'egg-view-nunjucks'; ...@@ -18,7 +18,6 @@ import 'egg-view-nunjucks';
import 'egg-socket.io'; import 'egg-socket.io';
import 'egg-redis'; import 'egg-redis';
import 'egg-cors'; import 'egg-cors';
import 'egg-mongoose';
import 'egg-jwt'; import 'egg-jwt';
import { EggPluginItem } from 'egg'; import { EggPluginItem } from 'egg';
declare module 'egg' { declare module 'egg' {
...@@ -39,7 +38,6 @@ declare module 'egg' { ...@@ -39,7 +38,6 @@ declare module 'egg' {
io?: EggPluginItem; io?: EggPluginItem;
redis?: EggPluginItem; redis?: EggPluginItem;
cors?: EggPluginItem; cors?: EggPluginItem;
mongoose?: EggPluginItem;
jwt?: EggPluginItem; jwt?: EggPluginItem;
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment