cloud-ide-model-schema
Version:
Pachage for schema management of Cloud IDEsys LMS
110 lines (109 loc) • 3.43 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CFeeReceiptTemplate = void 0;
var mongoose_1 = require("mongoose");
/**
* Fee Receipt Template Schema
* Customizable receipt templates with HTML editor
*/
/* SCHEMA START */
var fee_receipt_template = new mongoose_1.Schema({
feert_template_name: {
type: String,
required: true,
minlength: 1,
maxlength: 200,
trim: true,
comment: "Receipt template name"
},
feert_template_code: {
type: String,
required: false,
unique: true,
sparse: true,
maxlength: 50,
trim: true,
comment: "Unique receipt template code (auto-generated)"
},
feert_template_html: {
type: String,
required: true,
comment: "HTML content with placeholders for receipt data"
},
feert_template_type: {
type: String,
enum: ['PAYMENT', 'REFUND', 'PROVISIONAL'],
required: true,
comment: "Type of receipt template"
},
feert_template_for: {
type: String,
enum: ['STUDENT', 'OFFICE', 'BOTH'],
required: true,
default: 'BOTH',
comment: "Who this template is for"
},
feert_is_default: {
type: Boolean,
default: false,
comment: "Whether this is the default template for its type"
},
feert_entity_id_syen: {
type: mongoose_1.default.Schema.Types.ObjectId,
ref: "core_system_entity",
required: false,
default: null,
comment: "Entity/Organization this template belongs to (null = global)"
},
feert_status: {
type: String,
enum: ['ACTIVE', 'INACTIVE'],
required: true,
default: 'ACTIVE',
comment: "Template status"
},
feert_created_by_user: {
type: mongoose_1.default.Schema.Types.ObjectId,
ref: "auth_user_mst",
required: false,
default: null,
comment: "User who created this template"
},
feert_created_at: {
type: Date,
default: Date.now,
comment: "Template creation timestamp"
},
feert_updated_at: {
type: Date,
default: Date.now,
comment: "Template last update timestamp"
}
}, {
timestamps: false, // We handle timestamps manually
collection: "fee_receipt_template"
});
// Indexes
// Note: feert_template_code index is automatically created by unique: true
fee_receipt_template.index({ feert_entity_id_syen: 1 });
fee_receipt_template.index({ feert_template_type: 1 });
fee_receipt_template.index({ feert_status: 1 });
fee_receipt_template.index({ feert_is_default: 1 });
fee_receipt_template.index({ feert_created_at: -1 });
// Pre-save middleware to update feert_updated_at
fee_receipt_template.pre('save', function (next) {
this.feert_updated_at = new Date();
if (this.isNew) {
this.feert_created_at = new Date();
}
next();
});
// Pre-update middleware to update feert_updated_at
fee_receipt_template.pre(['updateOne', 'findOneAndUpdate', 'updateMany'], function (next) {
this.set({ feert_updated_at: new Date() });
next();
});
/* SCHEMA END */
/* MODEL START */
var CFeeReceiptTemplate = mongoose_1.default.models.fee_receipt_template || mongoose_1.default.model("fee_receipt_template", fee_receipt_template);
exports.CFeeReceiptTemplate = CFeeReceiptTemplate;