-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
KAN-3-user-service-add-session-management-to-user (#4)
* KAN-3 | Added session management logic to code base * prettier fixes
- Loading branch information
1 parent
c13f61e
commit e83ad87
Showing
11 changed files
with
80 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const mongoose = require('mongoose'); | ||
const { Schema } = mongoose; | ||
|
||
const sessionSchema = new Schema({ | ||
userId: { type: Schema.Types.ObjectId, required: true, ref: 'User' }, | ||
token: { type: String, required: true, unique: true }, | ||
created_at: { type: Date, default: Date.now }, | ||
}); | ||
|
||
module.exports = mongoose.model('Session', sessionSchema); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const Session = require('../models/session'); | ||
|
||
class SessionRepository { | ||
async createSession(data) { | ||
const session = new Session(data); | ||
return await session.save(); | ||
} | ||
async deleteSession(token) { | ||
return await Session.findOneAndDelete({ token }); | ||
} | ||
async findByToken(token) { | ||
return await Session.findOne({ token }); | ||
} | ||
} | ||
|
||
module.exports = new SessionRepository(); |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const sessionRepository = require('../repositories/sessionRepository'); | ||
|
||
class SessionService { | ||
async createSession(data) { | ||
return await sessionRepository.createSession(data); | ||
} | ||
async deleteSession(token) { | ||
return await sessionRepository.deleteSession(token); | ||
} | ||
async getSessionByToken(token) { | ||
return await sessionRepository.findByToken(token); | ||
} | ||
} | ||
|
||
module.exports = new SessionService(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters