-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#253 [Devops] Setup mongo and add telegram db Fail.
- Loading branch information
Showing
16 changed files
with
289 additions
and
139 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
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
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
55 changes: 55 additions & 0 deletions
55
backend-manager-student/src/share/schema/comment.schema.js
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,55 @@ | ||
//! LIBRARY | ||
const { Schema, model } = require('mongoose'); | ||
|
||
//! CONFIGS | ||
const CONSTANTS = require('../configs/constants'); | ||
|
||
/** | ||
* @author Nguyễn Tiến Tài | ||
* @created_at 13/04/2023 | ||
* @description Schema Comment Mongo | ||
*/ | ||
const commentSchema = new Schema({ | ||
user_id: { | ||
type: String, | ||
required: CONSTANTS.DELETED_ENABLE, | ||
}, | ||
book_id: { | ||
type: String, | ||
required: CONSTANTS.DELETED_ENABLE, | ||
}, | ||
posted: { | ||
type: Date, | ||
required: CONSTANTS.DELETED_ENABLE, | ||
}, | ||
content: { | ||
type: String, | ||
required: CONSTANTS.DELETED_ENABLE, | ||
maxLength: 150, | ||
}, | ||
parent_slug: { | ||
type: String, | ||
trim: CONSTANTS.DELETED_ENABLE, | ||
}, | ||
full_slug: { | ||
type: String, | ||
trim: CONSTANTS.DELETED_ENABLE, | ||
}, | ||
slug: { | ||
type: String, | ||
trim: CONSTANTS.DELETED_ENABLE, | ||
}, | ||
isdeleted: { | ||
type: Schema.Types.Boolean, | ||
default: CONSTANTS.DELETED_DISABLE, | ||
}, | ||
comment_replies_num: { | ||
type: Number, | ||
default: 0, | ||
}, | ||
|
||
}, { | ||
collection: CONSTANTS.MONGO_SCHEMA.COLLECTION_NAME, | ||
timestamps: CONSTANTS.DELETED_ENABLE, | ||
}); | ||
module.exports.COMMENT = model(CONSTANTS.MONGO.DOCUMENT_NAME, commentSchema); |
61 changes: 61 additions & 0 deletions
61
backend-manager-student/src/share/services/user_service/comment_service.js
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,61 @@ | ||
//! CONFIGS | ||
const CONSTANTS = require('../../configs/constants'); | ||
|
||
//! SCHEMA | ||
const { COMMENT } = require('../../schema/comment.schema'); | ||
|
||
//! MODEL | ||
const user_model = require('../../models/user.model'); | ||
|
||
/** | ||
* @author Nguyễn Tiến Tài | ||
* @created_at 13/04/2023 | ||
* @description create Comment | ||
* @function insert_comment | ||
*/ | ||
const insert_comment = async (data) => await COMMENT.create(data); | ||
|
||
/** | ||
* @author Nguyễn Tiến Tài | ||
* @created_at 13/04/2023 | ||
* @updated_at 14/04/2023 | ||
* @description List Comment | ||
* @function list_comment | ||
*/ | ||
const list_comment = async (match, search_data) => { | ||
const comments = await COMMENT.find(match, search_data).sort({ full_slug: 1 }).lean(); | ||
const userPromises = comments.map(async (comment) => { | ||
const user = await user_model.getStudentById( | ||
{ | ||
user_id: String(comment.user_id), | ||
isdeleted: CONSTANTS.DELETED_DISABLE, | ||
}, | ||
{ | ||
name: 'name', | ||
avatar_uri: 'avatar_uri', | ||
}, | ||
); | ||
return { | ||
...comment, | ||
full_name: user[0]?.name, | ||
avatar_uri_user: user[0]?.avatar_uri, | ||
}; | ||
}); | ||
// eslint-disable-next-line no-shadow | ||
const list_comment = await Promise.all(userPromises); | ||
return list_comment; | ||
}; | ||
|
||
/** | ||
* @author Nguyễn Tiến Tài | ||
* @created_at 13/04/2023 | ||
* @description get paren slug | ||
* @function get_paren_slug | ||
*/ | ||
const get_paren_slug = async (data) => await COMMENT.findOne(data).lean(); | ||
|
||
module.exports = { | ||
insert_comment, | ||
list_comment, | ||
get_paren_slug, | ||
}; |
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
Oops, something went wrong.