Add summary column to documents
This commit is contained in:
11
server/migrations/20240216182003-add-summary-to-documents.js
Normal file
11
server/migrations/20240216182003-add-summary-to-documents.js
Normal file
@@ -0,0 +1,11 @@
|
||||
module.exports = {
|
||||
up: async (queryInterface, Sequelize) => {
|
||||
await queryInterface.addColumn("documents", "summary", {
|
||||
type: Sequelize.TEXT,
|
||||
allowNull: true,
|
||||
});
|
||||
},
|
||||
down: async (queryInterface, Sequelize) => {
|
||||
await queryInterface.removeColumn("documents", "summary");
|
||||
},
|
||||
};
|
||||
@@ -217,6 +217,13 @@ class Document extends ParanoidModel<
|
||||
@Column
|
||||
title: string;
|
||||
|
||||
@Length({
|
||||
max: DocumentValidation.maxSummaryLength,
|
||||
msg: `Document summary must be ${DocumentValidation.maxSummaryLength} characters or less`,
|
||||
})
|
||||
@Column
|
||||
summary: string;
|
||||
|
||||
@Column(DataType.ARRAY(DataType.STRING))
|
||||
previousTitles: string[] = [];
|
||||
|
||||
@@ -985,6 +992,10 @@ class Document extends ParanoidModel<
|
||||
getTimestamp = () => Math.round(new Date(this.updatedAt).getTime() / 1000);
|
||||
|
||||
getSummary = () => {
|
||||
if (this.summary) {
|
||||
return this.summary;
|
||||
}
|
||||
|
||||
const plainText = DocumentHelper.toPlainText(this);
|
||||
const lines = compact(plainText.split("\n"));
|
||||
const notEmpty = lines.length >= 1;
|
||||
|
||||
Reference in New Issue
Block a user