@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.
@@ -0,0 +1,2 @@
1
+ export function up(queryInterface: any, Sequelize: any): Promise<void>;
2
+ export function down(queryInterface: any): Promise<void>;
@@ -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;
@@ -12,4 +12,5 @@ export interface IFileStorageAttributes extends IDefaultAttributes {
12
12
  fileSize?: number;
13
13
  storageUserId?: string;
14
14
  userDirectoryId?: string;
15
+ expiredAt?: Date;
15
16
  }
@@ -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
- resultId: string;
6
+ fileStorageId: string;
7
7
  userIds: string[];
8
8
  instituteId: string;
9
9
  academicCalendarId?: string;
10
10
  markSheetConfigurationId: string;
11
- stdId: string;
11
+ standardId: string;
12
12
  batchId: string;
13
13
  }
@@ -10,6 +10,7 @@ export interface IMarkSheetArrangement {
10
10
  subjectId: string;
11
11
  markConsiderType: string[];
12
12
  totalMark: number;
13
+ passingMarks: number;
13
14
  }
14
15
  export interface IMarkSheetConfigurationModelAttributes extends IDefaultAttributes, Document {
15
16
  id: string;
@@ -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
- resultId: { type: String, required: false },
40
+ fileStorageId: { type: String, required: false },
41
41
  markSheetConfigurationId: { type: String, required: false },
42
- stdId: { type: String, required: false },
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kipicore/dbcore",
3
- "version": "1.1.336",
3
+ "version": "1.1.338",
4
4
  "description": "Reusable DB core package with Postgres, MongoDB, models, services, interfaces, and types",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",