@ckstack/ck-lib-models
Version:
ckstack default database table sequelize models
326 lines (325 loc) • 12.9 kB
JavaScript
"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.File = void 0;
const sequelize_typescript_1 = require("sequelize-typescript");
const dk_lib_1 = require("@dkpkg/dk-lib");
const MyValues_1 = require("../MyValues");
const __autoFitString = (data, modelName) => {
const _data = data;
if (_data.name && dk_lib_1.CkUtils.getByteLength(_data.name) > 64) {
_data.name = dk_lib_1.CkUtils.stringCutByByte(_data.name, 64);
dk_lib_1.CkLogger.warnLog2(`${modelName}. name from [${data.name}] to [${_data.name}]`, MyValues_1.PROC_LHD.IP_LHD_HTTP);
}
if (_data.orig_name && dk_lib_1.CkUtils.getByteLength(_data.orig_name) > 255) {
_data.orig_name = dk_lib_1.CkUtils.stringCutByByte(_data.orig_name, 255);
dk_lib_1.CkLogger.warnLog2(`${modelName}. orig_name from [${data.orig_name}] to [${_data.orig_name}]`, MyValues_1.PROC_LHD.IP_LHD_HTTP);
}
if (_data.content_type && dk_lib_1.CkUtils.getByteLength(_data.content_type) > 128) {
_data.content_type = dk_lib_1.CkUtils.stringCutByByte(_data.content_type, 128);
dk_lib_1.CkLogger.warnLog2(`${modelName}. content_type from [${data.content_type}] to [${_data.content_type}]`, MyValues_1.PROC_LHD.IP_LHD_HTTP);
}
if (_data.file_path && dk_lib_1.CkUtils.getByteLength(_data.file_path) > 255) {
_data.file_path = dk_lib_1.CkUtils.stringCutByByte(_data.file_path, 255);
dk_lib_1.CkLogger.warnLog2(`${modelName}. file_path from [${data.file_path}] to [${_data.file_path}]`, MyValues_1.PROC_LHD.IP_LHD_HTTP);
}
if (_data.file_url_path && dk_lib_1.CkUtils.getByteLength(_data.file_url_path) > 255) {
_data.file_url_path = dk_lib_1.CkUtils.stringCutByByte(_data.file_url_path, 255);
dk_lib_1.CkLogger.warnLog2(`${modelName}. file_url_path from [${data.file_url_path}] to [${_data.file_url_path}]`, MyValues_1.PROC_LHD.IP_LHD_HTTP);
}
if (_data.thumbnail_path && dk_lib_1.CkUtils.getByteLength(_data.thumbnail_path) > 255) {
_data.thumbnail_path = dk_lib_1.CkUtils.stringCutByByte(_data.thumbnail_path, 255);
dk_lib_1.CkLogger.warnLog2(`${modelName}. thumbnail_path from [${data.thumbnail_path}] to [${_data.thumbnail_path}]`, MyValues_1.PROC_LHD.IP_LHD_HTTP);
}
if (_data.thumbnail_url_path && dk_lib_1.CkUtils.getByteLength(_data.thumbnail_url_path) > 255) {
_data.thumbnail_url_path = dk_lib_1.CkUtils.stringCutByByte(_data.thumbnail_url_path, 255);
dk_lib_1.CkLogger.warnLog2(`${modelName}. thumbnail_url_path from [${data.thumbnail_url_path}] to [${_data.thumbnail_url_path}]`, MyValues_1.PROC_LHD.IP_LHD_HTTP);
}
if (_data.description && dk_lib_1.CkUtils.getByteLength(_data.description) > 255) {
_data.description = dk_lib_1.CkUtils.stringCutByByte(_data.description, 255);
dk_lib_1.CkLogger.warnLog2(`${modelName}. description from [${data.description}] to [${_data.description}]`, MyValues_1.PROC_LHD.IP_LHD_HTTP);
}
if (_data.ipaddress && dk_lib_1.CkUtils.getByteLength(_data.ipaddress) > 32) {
_data.ipaddress = dk_lib_1.CkUtils.stringCutByByte(_data.ipaddress, 32);
dk_lib_1.CkLogger.warnLog2(`${modelName}. ipaddress from [${data.ipaddress}] to [${_data.ipaddress}]`, MyValues_1.PROC_LHD.IP_LHD_HTTP);
}
if (_data.user_id && dk_lib_1.CkUtils.getByteLength(_data.user_id) > 128) {
_data.user_id = dk_lib_1.CkUtils.stringCutByByte(_data.user_id, 128);
dk_lib_1.CkLogger.warnLog2(`${modelName}. user_id from [${data.user_id}] to [${_data.user_id}]`, MyValues_1.PROC_LHD.IP_LHD_HTTP);
}
};
let File = class File extends sequelize_typescript_1.Model {
static autoFitString(data) {
__autoFitString(data, 'File');
}
};
__decorate([
(0, sequelize_typescript_1.Column)({
field: 'id',
type: sequelize_typescript_1.DataType.INTEGER({ scale: 11 }).UNSIGNED,
primaryKey: true,
autoIncrement: true,
allowNull: false,
unique: true,
}),
__metadata("design:type", Number)
], File.prototype, "id", void 0);
__decorate([
(0, sequelize_typescript_1.Index)({ name: 'idx_rid', unique: true }),
(0, sequelize_typescript_1.Column)({
field: 'rid',
type: sequelize_typescript_1.DataType.STRING(32),
allowNull: false,
unique: true,
defaultValue: '',
}),
__metadata("design:type", String)
], File.prototype, "rid", void 0);
__decorate([
(0, sequelize_typescript_1.Column)({
field: 'name',
type: sequelize_typescript_1.DataType.STRING(64),
allowNull: false,
defaultValue: '',
}),
__metadata("design:type", String)
], File.prototype, "name", void 0);
__decorate([
(0, sequelize_typescript_1.Column)({
field: 'orig_name',
type: sequelize_typescript_1.DataType.STRING(255),
allowNull: false,
defaultValue: '',
}),
__metadata("design:type", String)
], File.prototype, "orig_name", void 0);
__decorate([
(0, sequelize_typescript_1.Column)({
field: 'content_type',
type: sequelize_typescript_1.DataType.STRING(128),
allowNull: false,
defaultValue: '',
}),
__metadata("design:type", String)
], File.prototype, "content_type", void 0);
__decorate([
(0, sequelize_typescript_1.Column)({
field: 'file_path',
type: sequelize_typescript_1.DataType.STRING(255),
allowNull: false,
defaultValue: '',
}),
__metadata("design:type", String)
], File.prototype, "file_path", void 0);
__decorate([
(0, sequelize_typescript_1.Column)({
field: 'file_url_path',
type: sequelize_typescript_1.DataType.STRING(255),
allowNull: false,
defaultValue: '',
}),
__metadata("design:type", String)
], File.prototype, "file_url_path", void 0);
__decorate([
(0, sequelize_typescript_1.Column)({
field: 's3_bucket',
type: sequelize_typescript_1.DataType.STRING(128),
defaultValue: '',
}),
__metadata("design:type", String)
], File.prototype, "s3_bucket", void 0);
__decorate([
(0, sequelize_typescript_1.Column)({
field: 's3_obj_key',
type: sequelize_typescript_1.DataType.STRING(255),
defaultValue: '',
}),
__metadata("design:type", String)
], File.prototype, "s3_obj_key", void 0);
__decorate([
(0, sequelize_typescript_1.Column)({
field: 's3_region',
type: sequelize_typescript_1.DataType.STRING(64),
defaultValue: '',
}),
__metadata("design:type", String)
], File.prototype, "s3_region", void 0);
__decorate([
(0, sequelize_typescript_1.Column)({
field: 'file_size',
type: sequelize_typescript_1.DataType.INTEGER.UNSIGNED,
allowNull: false,
defaultValue: 0,
}),
__metadata("design:type", Number)
], File.prototype, "file_size", void 0);
__decorate([
(0, sequelize_typescript_1.Column)({
field: 'width',
type: sequelize_typescript_1.DataType.INTEGER.UNSIGNED,
allowNull: false,
defaultValue: 0,
}),
__metadata("design:type", Number)
], File.prototype, "width", void 0);
__decorate([
(0, sequelize_typescript_1.Column)({
field: 'height',
type: sequelize_typescript_1.DataType.INTEGER.UNSIGNED,
allowNull: false,
defaultValue: 0,
}),
__metadata("design:type", Number)
], File.prototype, "height", void 0);
__decorate([
(0, sequelize_typescript_1.Column)({
field: 'thumbnail_path',
type: sequelize_typescript_1.DataType.STRING(255),
defaultValue: '',
}),
__metadata("design:type", String)
], File.prototype, "thumbnail_path", void 0);
__decorate([
(0, sequelize_typescript_1.Column)({
field: 'thumbnail_url_path',
type: sequelize_typescript_1.DataType.STRING(255),
defaultValue: '',
}),
__metadata("design:type", String)
], File.prototype, "thumbnail_url_path", void 0);
__decorate([
(0, sequelize_typescript_1.Column)({
field: 'thumbnail_s3_bucket',
type: sequelize_typescript_1.DataType.STRING(128),
defaultValue: '',
}),
__metadata("design:type", String)
], File.prototype, "thumbnail_s3_bucket", void 0);
__decorate([
(0, sequelize_typescript_1.Column)({
field: 'thumbnail_s3_region',
type: sequelize_typescript_1.DataType.STRING(64),
defaultValue: '',
}),
__metadata("design:type", String)
], File.prototype, "thumbnail_s3_region", void 0);
__decorate([
(0, sequelize_typescript_1.Column)({
field: 'thumbnail_s3_obj_key',
type: sequelize_typescript_1.DataType.STRING(255),
defaultValue: '',
}),
__metadata("design:type", String)
], File.prototype, "thumbnail_s3_obj_key", void 0);
__decorate([
(0, sequelize_typescript_1.Column)({
field: 'thumbnail_size',
type: sequelize_typescript_1.DataType.INTEGER.UNSIGNED,
defaultValue: 0,
}),
__metadata("design:type", Number)
], File.prototype, "thumbnail_size", void 0);
__decorate([
(0, sequelize_typescript_1.Column)({
field: 'thumbnail_width',
type: sequelize_typescript_1.DataType.INTEGER.UNSIGNED,
defaultValue: 0,
}),
__metadata("design:type", Number)
], File.prototype, "thumbnail_width", void 0);
__decorate([
(0, sequelize_typescript_1.Column)({
field: 'thumbnail_height',
type: sequelize_typescript_1.DataType.INTEGER.UNSIGNED,
defaultValue: 0,
}),
__metadata("design:type", Number)
], File.prototype, "thumbnail_height", void 0);
__decorate([
(0, sequelize_typescript_1.Column)({
field: 'description',
type: sequelize_typescript_1.DataType.STRING(255),
defaultValue: '',
}),
__metadata("design:type", String)
], File.prototype, "description", void 0);
__decorate([
(0, sequelize_typescript_1.Column)({
field: 'ipaddress',
type: sequelize_typescript_1.DataType.STRING(32),
allowNull: false,
defaultValue: '',
}),
__metadata("design:type", String)
], File.prototype, "ipaddress", void 0);
__decorate([
(0, sequelize_typescript_1.Column)({
field: 'used',
type: sequelize_typescript_1.DataType.JSON,
defaultValue: {},
}),
__metadata("design:type", Object)
], File.prototype, "used", void 0);
__decorate([
(0, sequelize_typescript_1.Index)('idx_user_id'),
(0, sequelize_typescript_1.Column)({
field: 'user_id',
type: sequelize_typescript_1.DataType.STRING(128),
allowNull: false,
defaultValue: '',
}),
__metadata("design:type", String)
], File.prototype, "user_id", void 0);
__decorate([
(0, sequelize_typescript_1.Column)({
field: 'deleted',
type: sequelize_typescript_1.DataType.ENUM(dk_lib_1.CkValue.YES_OR_NO.YES, dk_lib_1.CkValue.YES_OR_NO.NO),
allowNull: false,
defaultValue: dk_lib_1.CkValue.YES_OR_NO.NO,
}),
__metadata("design:type", Number)
], File.prototype, "deleted", void 0);
__decorate([
(0, sequelize_typescript_1.Column)({
field: 'c_date',
type: sequelize_typescript_1.DataType.DATE,
allowNull: false,
defaultValue: new Date(),
}),
__metadata("design:type", Date)
], File.prototype, "c_date", void 0);
__decorate([
(0, sequelize_typescript_1.Column)({
field: 'u_date',
type: sequelize_typescript_1.DataType.DATE,
allowNull: true,
defaultValue: new Date(),
}),
__metadata("design:type", Date)
], File.prototype, "u_date", void 0);
__decorate([
sequelize_typescript_1.BeforeCreate,
sequelize_typescript_1.BeforeUpdate,
sequelize_typescript_1.BeforeSave,
sequelize_typescript_1.BeforeUpsert,
__metadata("design:type", Function),
__metadata("design:paramtypes", [File]),
__metadata("design:returntype", void 0)
], File, "autoFitString", null);
File = __decorate([
(0, sequelize_typescript_1.Table)({
tableName: 'tbl_files',
freezeTableName: true,
underscored: true,
timestamps: false,
})
], File);
exports.File = File;