@kipicore/dbcore 1.1.336 → 1.1.338
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/db/psql/migrations/20260324084437-add-expired-at-file-storage-model.d.ts +2 -0
- package/dist/db/psql/migrations/20260324084437-add-expired-at-file-storage-model.js +21 -0
- package/dist/helpers/s3Uploader.js +16 -0
- package/dist/interfaces/fileStorageInterface.d.ts +1 -0
- package/dist/interfaces/finalMarkSheetInterface.d.ts +2 -2
- package/dist/interfaces/markSheetConfigurationInterface.d.ts +1 -0
- package/dist/models/mongodb/finalMarkSheetModel.js +2 -2
- package/dist/models/mongodb/markSheetConfigurationModel.js +1 -0
- package/dist/models/psql/fileStorageModel.js +5 -0
- package/package.json +1 -1
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const up = async (queryInterface, Sequelize) => {
|
|
3
|
+
const table = await queryInterface.describeTable('file_storage');
|
|
4
|
+
if (!table.expired_at) {
|
|
5
|
+
await queryInterface.addColumn('file_storage', 'expired_at', {
|
|
6
|
+
type: Sequelize.DATE,
|
|
7
|
+
allowNull: true,
|
|
8
|
+
field: 'expired_at',
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
const down = async (queryInterface) => {
|
|
13
|
+
const table = await queryInterface.describeTable('file_storage');
|
|
14
|
+
if (table.expired_at) {
|
|
15
|
+
await queryInterface.removeColumn('file_storage', 'expired_at');
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
module.exports = {
|
|
19
|
+
up,
|
|
20
|
+
down,
|
|
21
|
+
};
|
|
@@ -11,6 +11,8 @@ const aws_1 = require("../configs/aws");
|
|
|
11
11
|
const env_1 = require("../configs/env");
|
|
12
12
|
const client_s3_1 = require("@aws-sdk/client-s3");
|
|
13
13
|
const s3_request_presigner_1 = require("@aws-sdk/s3-request-presigner");
|
|
14
|
+
const date_fns_1 = require("date-fns");
|
|
15
|
+
const psql_1 = require("../models/psql");
|
|
14
16
|
const uploadFileToS3 = async (localFilePath, s3Key, s3Bucket = env_1.ENV_VARIABLE.AWS_BUCKET_NAME) => {
|
|
15
17
|
try {
|
|
16
18
|
const fileContent = fs_1.default.readFileSync(localFilePath);
|
|
@@ -35,12 +37,26 @@ const uploadFileToS3 = async (localFilePath, s3Key, s3Bucket = env_1.ENV_VARIABL
|
|
|
35
37
|
};
|
|
36
38
|
exports.uploadFileToS3 = uploadFileToS3;
|
|
37
39
|
const getPresignedUrl = async (bucket, fileStorage, expiresIn = 60 * 60 * 24) => {
|
|
40
|
+
if (fileStorage.expiredAt && fileStorage.filePath) {
|
|
41
|
+
const currentDate = (0, date_fns_1.getTime)((0, date_fns_1.subMinutes)(new Date(), 5));
|
|
42
|
+
const expireDate = (0, date_fns_1.getTime)(new Date(fileStorage.expiredAt));
|
|
43
|
+
if (currentDate < expireDate)
|
|
44
|
+
return fileStorage.filePath;
|
|
45
|
+
}
|
|
38
46
|
const s3Key = `${fileStorage.storagePath}/${fileStorage.storageFileName}`;
|
|
39
47
|
const command = new client_s3_1.GetObjectCommand({
|
|
40
48
|
Bucket: bucket,
|
|
41
49
|
Key: s3Key,
|
|
42
50
|
});
|
|
43
51
|
const signedUrl = await (0, s3_request_presigner_1.getSignedUrl)(aws_1.s3, command, { expiresIn }); // in seconds
|
|
52
|
+
if (fileStorage.id) {
|
|
53
|
+
psql_1.FileStorageModel.update({
|
|
54
|
+
filePath: signedUrl,
|
|
55
|
+
expiredAt: (0, date_fns_1.addDays)(new Date(), 1),
|
|
56
|
+
}, {
|
|
57
|
+
where: { id: fileStorage.id },
|
|
58
|
+
});
|
|
59
|
+
}
|
|
44
60
|
return signedUrl;
|
|
45
61
|
};
|
|
46
62
|
exports.getPresignedUrl = getPresignedUrl;
|
|
@@ -3,11 +3,11 @@ import { IDefaultAttributes } from './commonInterface';
|
|
|
3
3
|
export interface IFinalMarkSheetModelAttributes extends IDefaultAttributes, Document {
|
|
4
4
|
id: string;
|
|
5
5
|
date: Date;
|
|
6
|
-
|
|
6
|
+
fileStorageId: string;
|
|
7
7
|
userIds: string[];
|
|
8
8
|
instituteId: string;
|
|
9
9
|
academicCalendarId?: string;
|
|
10
10
|
markSheetConfigurationId: string;
|
|
11
|
-
|
|
11
|
+
standardId: string;
|
|
12
12
|
batchId: string;
|
|
13
13
|
}
|
|
@@ -37,9 +37,9 @@ const mongoose_1 = __importStar(require("mongoose"));
|
|
|
37
37
|
const finalMarkSheetModelSchema = new mongoose_1.Schema({
|
|
38
38
|
instituteId: { type: String, required: false },
|
|
39
39
|
academicCalendarId: { type: String, required: false },
|
|
40
|
-
|
|
40
|
+
fileStorageId: { type: String, required: false },
|
|
41
41
|
markSheetConfigurationId: { type: String, required: false },
|
|
42
|
-
|
|
42
|
+
standardId: { type: String, required: false },
|
|
43
43
|
batchId: { type: String, required: false },
|
|
44
44
|
userIds: { type: [String], default: [] },
|
|
45
45
|
date: { type: Date, required: false },
|
|
@@ -44,6 +44,7 @@ const markSheetArrangementSchema = new mongoose_1.Schema({
|
|
|
44
44
|
subjectId: { type: String, required: false },
|
|
45
45
|
markConsiderType: { type: [String], default: [] },
|
|
46
46
|
totalMark: { type: Number, required: false },
|
|
47
|
+
passingMarks: { type: Number, required: false },
|
|
47
48
|
}, { _id: false });
|
|
48
49
|
const marksConfigurationModelSchema = new mongoose_1.Schema({
|
|
49
50
|
instituteId: { type: String, required: false },
|
|
@@ -96,6 +96,11 @@ FileStorageModel.init({
|
|
|
96
96
|
field: 'user_directory_id',
|
|
97
97
|
allowNull: true,
|
|
98
98
|
},
|
|
99
|
+
expiredAt: {
|
|
100
|
+
type: sequelize_1.DataTypes.DATE,
|
|
101
|
+
field: 'expired_at',
|
|
102
|
+
allowNull: true,
|
|
103
|
+
},
|
|
99
104
|
}, {
|
|
100
105
|
modelName: 'FileStorageModel',
|
|
101
106
|
tableName: 'file_storage',
|
package/package.json
CHANGED