Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
egg-websocket
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
huanglu
egg-websocket
Commits
0cfce6d0
Commit
0cfce6d0
authored
Mar 08, 2021
by
huanglu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 去除mongo
parent
2ad1654c
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
42 additions
and
42 deletions
+42
-42
ChatRoom.ts
app/model/ChatRoom.ts
+17
-16
ChatUser.ts
app/model/ChatUser.ts
+14
-13
GCounter.ts
app/model/GCounter.ts
+10
-9
package.json
package.json
+1
-1
plugin.d.ts
typings/config/plugin.d.ts
+0
-3
No files found.
app/model/ChatRoom.ts
View file @
0cfce6d0
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);
};
};
app/model/ChatUser.ts
View file @
0cfce6d0
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;
};
};
app/model/GCounter.ts
View file @
0cfce6d0
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);
};
};
package.json
View file @
0cfce6d0
...
@@ -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"
,
...
...
typings/config/plugin.d.ts
View file @
0cfce6d0
...
@@ -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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment