flexbiz-server
Version:
Flexible Server
8 lines (7 loc) • 2.43 kB
JavaScript
'use strict';const moment=require("moment"),chamcongSchema=new Schema({id_app:{type:String,required:!0,maxlength:1024},ma_bp:{type:String,required:!0,uppercase:!0,maxlength:32,trim:!0},ma_nv:{type:String,required:!0,uppercase:!0,maxlength:32,trim:!0},ten_nv:String,ma_loai_cong:{type:String,required:!0,uppercase:!0,maxlength:32,trim:!0},ngay:Date,gio_vao:Date,gio_ra:Date,gio_vao_f:String,gio_ra_f:String,ghi_chu:String,exfields:Schema.Types.Mixed,status:{type:Boolean,default:!0},device_user_id:String,
id_checkin:String,date_created:{type:Date,default:Date.now},date_updated:{type:Date,default:Date.now},user_created:{type:String,default:""},user_updated:{type:String,default:""}});
chamcongSchema.pre("save",function($next$$){console.log("handle du lieu cham cong",this);try{if(this.gio_vao_f){let $gio_vao$$=moment(this.ngay),[$gio$$,$phut$$]=this.gio_vao_f.split(":");if($gio$$){$gio$$=Number($gio$$);if(isNaN($gio$$))return $next$$("Gi\u1edd v\u00e0o kh\u00f4ng h\u1ee3p l\u1ec7");$gio_vao$$=$gio_vao$$.hours($gio$$)}else return $next$$("Gi\u1edd v\u00e0o kh\u00f4ng h\u1ee3p l\u1ec7");$phut$$?($phut$$=Number($phut$$),isNaN($phut$$)&&($phut$$=0)):$phut$$=0;$gio_vao$$=$gio_vao$$.minutes($phut$$);
this.gio_vao=$gio_vao$$.toDate()}if(this.gio_ra_f){let $gio_ra$$=moment(this.ngay),[$gio$$,$phut$$]=this.gio_ra_f.split(":");if($gio$$){$gio$$=Number($gio$$);if(isNaN($gio$$))return $next$$("Gi\u1edd ra kh\u00f4ng h\u1ee3p l\u1ec7");$gio_ra$$=$gio_ra$$.hours($gio$$)}else return $next$$("Gi\u1edd ra kh\u00f4ng h\u1ee3p l\u1ec7");$phut$$?($phut$$=Number($phut$$),isNaN($phut$$)||($phut$$=0)):$phut$$=0;$gio_ra$$=$gio_ra$$.minutes($phut$$);this.gio_ra=$gio_ra$$.toDate()}}catch($e$$){return console.error("chamcong kh\u00f4ng h\u1ee3p l\u1ec7",
this),$next$$({error:"C\u00f4ng kh\u00f4ng h\u1ee3p l\u1ec7"})}$next$$()});
(global.configs||{}).createIndexes&&(chamcongSchema.index({id_app:1,ma_nv:1,ma_loai_cong:1}),chamcongSchema.index({ngay:1}),chamcongSchema.index({ma_bp:1}),chamcongSchema.index({gio_vao:1}),chamcongSchema.index({gio_ra:1}),chamcongSchema.index({ma_nv:"text",ten_nv:"text",ghi_chu:"text"},{name:"chamcong_index_text"}),chamcongSchema.index({device_user_id:1}),chamcongSchema.index({id_checkin:1}),chamcongSchema.index({status:1}),chamcongSchema.index({user_created:1,visible_to:1,visible_to_users:1}));
const model=mongoose.models.chamcong||mongoose.model("chamcong",chamcongSchema);module.exports=model;