@fesmex/models 0.1.4 → 0.1.5

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 { default as Announcement } from "./models/Announcements";
2
+ export type { AnnouncementType } from "./models/Announcements";
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Announcement = void 0;
7
+ var Announcements_1 = require("./models/Announcements");
8
+ Object.defineProperty(exports, "Announcement", { enumerable: true, get: function () { return __importDefault(Announcements_1).default; } });
@@ -0,0 +1,17 @@
1
+ import mongoose from "mongoose";
2
+ import { UserRole } from "../../users/models/Users";
3
+ export interface AnnouncementType {
4
+ created_by: mongoose.Types.ObjectId;
5
+ updated_by?: mongoose.Types.ObjectId;
6
+ deleted_by?: mongoose.Types.ObjectId;
7
+ created_at: Date;
8
+ updated_at?: Date;
9
+ deleted_at?: Date;
10
+ title: string;
11
+ text: string;
12
+ roles: UserRole[];
13
+ }
14
+ declare const _default: mongoose.Model<AnnouncementType, {}, {}, {}, mongoose.Document<unknown, {}, AnnouncementType> & AnnouncementType & {
15
+ _id: mongoose.Types.ObjectId;
16
+ }, any>;
17
+ export default _default;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const mongoose_1 = require("mongoose");
4
+ const Users_1 = require("../../users/models/Users");
5
+ const announcementSchema = new mongoose_1.Schema({
6
+ created_by: {
7
+ type: mongoose_1.Schema.Types.ObjectId,
8
+ ref: "User",
9
+ required: true,
10
+ },
11
+ updated_by: {
12
+ type: mongoose_1.Schema.Types.ObjectId,
13
+ ref: "User",
14
+ },
15
+ deleted_by: {
16
+ type: mongoose_1.Schema.Types.ObjectId,
17
+ ref: "User",
18
+ },
19
+ created_at: {
20
+ type: Date,
21
+ default: Date.now,
22
+ },
23
+ updated_at: Date,
24
+ deleted_at: Date,
25
+ title: {
26
+ type: String,
27
+ required: true,
28
+ trim: true,
29
+ },
30
+ text: {
31
+ type: String,
32
+ required: true,
33
+ trim: true,
34
+ },
35
+ roles: {
36
+ type: [String],
37
+ enum: Object.values(Users_1.UserRole),
38
+ required: true,
39
+ validate: {
40
+ validator: (roles) => roles.length > 0,
41
+ message: "At least one user role must be assigned.",
42
+ },
43
+ },
44
+ });
45
+ exports.default = (0, mongoose_1.model)("Announcement", announcementSchema, "announcements");
@@ -0,0 +1,4 @@
1
+ export { default as Customer } from "./models/Customers";
2
+ export type { CustomerType, CustomerStatus } from "./models/Customers";
3
+ export { default as FiscalProfile } from "./models/FiscalProfileType";
4
+ export type { FiscalProfileType } from "./models/FiscalProfileType";
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.FiscalProfile = exports.Customer = void 0;
7
+ var Customers_1 = require("./models/Customers");
8
+ Object.defineProperty(exports, "Customer", { enumerable: true, get: function () { return __importDefault(Customers_1).default; } });
9
+ var FiscalProfileType_1 = require("./models/FiscalProfileType");
10
+ Object.defineProperty(exports, "FiscalProfile", { enumerable: true, get: function () { return __importDefault(FiscalProfileType_1).default; } });
@@ -0,0 +1,22 @@
1
+ import mongoose from "mongoose";
2
+ export declare enum CustomerStatus {
3
+ ACTIVE = "active",
4
+ INACTIVE = "inactive",
5
+ BANNED = "banned"
6
+ }
7
+ export interface CustomerType {
8
+ first_name: string;
9
+ last_name: string;
10
+ email: string;
11
+ mobile?: string;
12
+ password: string;
13
+ status: CustomerStatus;
14
+ fiscal_profile_id?: mongoose.Types.ObjectId;
15
+ created_at: Date;
16
+ updated_at?: Date;
17
+ deleted_at?: Date;
18
+ }
19
+ declare const _default: mongoose.Model<CustomerType, {}, {}, {}, mongoose.Document<unknown, {}, CustomerType> & CustomerType & {
20
+ _id: mongoose.Types.ObjectId;
21
+ }, any>;
22
+ export default _default;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.CustomerStatus = void 0;
7
+ const mongoose_1 = require("mongoose");
8
+ const bcryptjs_1 = __importDefault(require("bcryptjs"));
9
+ var CustomerStatus;
10
+ (function (CustomerStatus) {
11
+ CustomerStatus["ACTIVE"] = "active";
12
+ CustomerStatus["INACTIVE"] = "inactive";
13
+ CustomerStatus["BANNED"] = "banned";
14
+ })(CustomerStatus || (exports.CustomerStatus = CustomerStatus = {}));
15
+ const customerSchema = new mongoose_1.Schema({
16
+ first_name: { type: String, required: true },
17
+ last_name: { type: String, required: true },
18
+ email: { type: String, required: true, unique: true },
19
+ mobile: { type: String },
20
+ password: { type: String, required: true, select: false },
21
+ status: {
22
+ type: String,
23
+ enum: Object.values(CustomerStatus),
24
+ default: CustomerStatus.ACTIVE,
25
+ },
26
+ fiscal_profile_id: { type: mongoose_1.Schema.Types.ObjectId, ref: "FiscalProfile" },
27
+ created_at: { type: Date, default: Date.now },
28
+ updated_at: { type: Date },
29
+ deleted_at: { type: Date },
30
+ });
31
+ // Hash password
32
+ customerSchema.pre("save", async function (next) {
33
+ if (this.isModified("password")) {
34
+ this.password = await bcryptjs_1.default.hash(this.password, 12);
35
+ }
36
+ next();
37
+ });
38
+ exports.default = (0, mongoose_1.model)("Customer", customerSchema, "customers");
@@ -0,0 +1,15 @@
1
+ import mongoose from "mongoose";
2
+ export interface FiscalProfileType {
3
+ customer_id: mongoose.Types.ObjectId;
4
+ rfc: string;
5
+ razon_social: string;
6
+ uso_cfdi: string;
7
+ regimen_fiscal: string;
8
+ cp: string;
9
+ created_at: Date;
10
+ updated_at?: Date;
11
+ }
12
+ declare const _default: mongoose.Model<FiscalProfileType, {}, {}, {}, mongoose.Document<unknown, {}, FiscalProfileType> & FiscalProfileType & {
13
+ _id: mongoose.Types.ObjectId;
14
+ }, any>;
15
+ export default _default;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const mongoose_1 = require("mongoose");
4
+ const fiscalProfileSchema = new mongoose_1.Schema({
5
+ customer_id: { type: mongoose_1.Schema.Types.ObjectId, ref: "Customer", required: true },
6
+ rfc: { type: String, required: true },
7
+ razon_social: { type: String, required: true },
8
+ uso_cfdi: { type: String, required: true },
9
+ regimen_fiscal: { type: String, required: true },
10
+ cp: { type: String, required: true },
11
+ created_at: { type: Date, default: Date.now },
12
+ updated_at: { type: Date },
13
+ });
14
+ exports.default = (0, mongoose_1.model)("FiscalProfile", fiscalProfileSchema, "fiscal_profiles");
package/dist/index.d.ts CHANGED
@@ -1,3 +1,8 @@
1
1
  export * from "./clients";
2
2
  export * from "./inventory";
3
3
  export * from "./quotes";
4
+ export * from "./customers";
5
+ export * from "./orders";
6
+ export * from "./sap";
7
+ export * from "./announcements";
8
+ export * from "./users";
package/dist/index.js CHANGED
@@ -17,3 +17,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./clients"), exports);
18
18
  __exportStar(require("./inventory"), exports);
19
19
  __exportStar(require("./quotes"), exports);
20
+ __exportStar(require("./customers"), exports);
21
+ __exportStar(require("./orders"), exports);
22
+ __exportStar(require("./sap"), exports);
23
+ __exportStar(require("./announcements"), exports);
24
+ __exportStar(require("./users"), exports);
@@ -0,0 +1,4 @@
1
+ export { default as Order } from "./models/Orders";
2
+ export { default as OrderStatusLog } from "./models/OrderStatusLogs";
3
+ export { OrderStatus } from "./models/Orders";
4
+ export type { OrderStatusLogType } from "./models/OrderStatusLogs";
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.OrderStatus = exports.OrderStatusLog = exports.Order = void 0;
7
+ var Orders_1 = require("./models/Orders");
8
+ Object.defineProperty(exports, "Order", { enumerable: true, get: function () { return __importDefault(Orders_1).default; } });
9
+ var OrderStatusLogs_1 = require("./models/OrderStatusLogs");
10
+ Object.defineProperty(exports, "OrderStatusLog", { enumerable: true, get: function () { return __importDefault(OrderStatusLogs_1).default; } });
11
+ var Orders_2 = require("./models/Orders");
12
+ Object.defineProperty(exports, "OrderStatus", { enumerable: true, get: function () { return Orders_2.OrderStatus; } });
@@ -0,0 +1,13 @@
1
+ import { Types } from "mongoose";
2
+ import { OrderStatus } from "./Orders";
3
+ export interface OrderStatusLogType {
4
+ order_id: Types.ObjectId;
5
+ status: OrderStatus;
6
+ changed_by: Types.ObjectId;
7
+ changed_at: Date;
8
+ note?: string;
9
+ }
10
+ declare const _default: import("mongoose").Model<OrderStatusLogType, {}, {}, {}, import("mongoose").Document<unknown, {}, OrderStatusLogType> & OrderStatusLogType & {
11
+ _id: Types.ObjectId;
12
+ }, any>;
13
+ export default _default;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const mongoose_1 = require("mongoose");
4
+ const Orders_1 = require("./Orders");
5
+ const orderStatusLogSchema = new mongoose_1.Schema({
6
+ order_id: {
7
+ type: mongoose_1.Schema.Types.ObjectId,
8
+ ref: "Order",
9
+ required: true,
10
+ },
11
+ status: {
12
+ type: String,
13
+ enum: Object.values(Orders_1.OrderStatus),
14
+ required: true,
15
+ },
16
+ changed_by: {
17
+ type: mongoose_1.Schema.Types.ObjectId,
18
+ ref: "User",
19
+ required: true,
20
+ },
21
+ changed_at: {
22
+ type: Date,
23
+ default: Date.now,
24
+ },
25
+ note: {
26
+ type: String,
27
+ },
28
+ });
29
+ exports.default = (0, mongoose_1.model)("OrderStatusLog", orderStatusLogSchema, "order_status_logs");
@@ -0,0 +1,98 @@
1
+ import { Schema } from "mongoose";
2
+ export declare enum OrderStatus {
3
+ PENDING = "pending",
4
+ CONFIRMED = "confirmed",
5
+ SHIPPED = "shipped",
6
+ CANCELLED = "cancelled",
7
+ COMPLETED = "completed"
8
+ }
9
+ declare const _default: import("mongoose").Model<{
10
+ created_at: Date;
11
+ status: OrderStatus;
12
+ total: number;
13
+ customer_id: import("mongoose").Types.ObjectId;
14
+ items: import("mongoose").Types.DocumentArray<{
15
+ article_id: import("mongoose").Types.ObjectId;
16
+ quantity: number;
17
+ unit_price: number;
18
+ total: number;
19
+ }>;
20
+ updated_at?: Date;
21
+ notes?: string;
22
+ tracking_number?: string;
23
+ }, {}, {}, {}, import("mongoose").Document<unknown, {}, {
24
+ created_at: Date;
25
+ status: OrderStatus;
26
+ total: number;
27
+ customer_id: import("mongoose").Types.ObjectId;
28
+ items: import("mongoose").Types.DocumentArray<{
29
+ article_id: import("mongoose").Types.ObjectId;
30
+ quantity: number;
31
+ unit_price: number;
32
+ total: number;
33
+ }>;
34
+ updated_at?: Date;
35
+ notes?: string;
36
+ tracking_number?: string;
37
+ }> & {
38
+ created_at: Date;
39
+ status: OrderStatus;
40
+ total: number;
41
+ customer_id: import("mongoose").Types.ObjectId;
42
+ items: import("mongoose").Types.DocumentArray<{
43
+ article_id: import("mongoose").Types.ObjectId;
44
+ quantity: number;
45
+ unit_price: number;
46
+ total: number;
47
+ }>;
48
+ updated_at?: Date;
49
+ notes?: string;
50
+ tracking_number?: string;
51
+ } & {
52
+ _id: import("mongoose").Types.ObjectId;
53
+ }, Schema<any, import("mongoose").Model<any, any, any, any, any, any>, {}, {}, {}, {}, import("mongoose").DefaultSchemaOptions, {
54
+ created_at: Date;
55
+ status: OrderStatus;
56
+ total: number;
57
+ customer_id: import("mongoose").Types.ObjectId;
58
+ items: import("mongoose").Types.DocumentArray<{
59
+ article_id: import("mongoose").Types.ObjectId;
60
+ quantity: number;
61
+ unit_price: number;
62
+ total: number;
63
+ }>;
64
+ updated_at?: Date;
65
+ notes?: string;
66
+ tracking_number?: string;
67
+ }, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<{
68
+ created_at: Date;
69
+ status: OrderStatus;
70
+ total: number;
71
+ customer_id: import("mongoose").Types.ObjectId;
72
+ items: import("mongoose").Types.DocumentArray<{
73
+ article_id: import("mongoose").Types.ObjectId;
74
+ quantity: number;
75
+ unit_price: number;
76
+ total: number;
77
+ }>;
78
+ updated_at?: Date;
79
+ notes?: string;
80
+ tracking_number?: string;
81
+ }>> & import("mongoose").FlatRecord<{
82
+ created_at: Date;
83
+ status: OrderStatus;
84
+ total: number;
85
+ customer_id: import("mongoose").Types.ObjectId;
86
+ items: import("mongoose").Types.DocumentArray<{
87
+ article_id: import("mongoose").Types.ObjectId;
88
+ quantity: number;
89
+ unit_price: number;
90
+ total: number;
91
+ }>;
92
+ updated_at?: Date;
93
+ notes?: string;
94
+ tracking_number?: string;
95
+ }> & {
96
+ _id: import("mongoose").Types.ObjectId;
97
+ }>>;
98
+ export default _default;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OrderStatus = void 0;
4
+ const mongoose_1 = require("mongoose");
5
+ var OrderStatus;
6
+ (function (OrderStatus) {
7
+ OrderStatus["PENDING"] = "pending";
8
+ OrderStatus["CONFIRMED"] = "confirmed";
9
+ OrderStatus["SHIPPED"] = "shipped";
10
+ OrderStatus["CANCELLED"] = "cancelled";
11
+ OrderStatus["COMPLETED"] = "completed";
12
+ })(OrderStatus || (exports.OrderStatus = OrderStatus = {}));
13
+ const orderItemSchema = new mongoose_1.Schema({
14
+ article_id: { type: mongoose_1.Schema.Types.ObjectId, ref: "Article", required: true },
15
+ quantity: { type: Number, required: true },
16
+ unit_price: { type: Number, required: true },
17
+ total: { type: Number, required: true },
18
+ }, { _id: false });
19
+ const orderSchema = new mongoose_1.Schema({
20
+ customer_id: { type: mongoose_1.Schema.Types.ObjectId, ref: "Customer", required: true },
21
+ items: [orderItemSchema],
22
+ status: {
23
+ type: String,
24
+ enum: Object.values(OrderStatus),
25
+ default: OrderStatus.PENDING,
26
+ },
27
+ tracking_number: { type: String },
28
+ total: { type: Number, required: true },
29
+ notes: { type: String },
30
+ created_at: { type: Date, default: Date.now },
31
+ updated_at: { type: Date },
32
+ });
33
+ exports.default = (0, mongoose_1.model)("Order", orderSchema, "orders");
@@ -0,0 +1 @@
1
+ export { SyncLog, SyncLogAction, SyncLogStatus, SyncLogType } from "./models/SyncLog";
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SyncLogType = exports.SyncLogStatus = exports.SyncLogAction = exports.SyncLog = void 0;
4
+ var SyncLog_1 = require("./models/SyncLog");
5
+ Object.defineProperty(exports, "SyncLog", { enumerable: true, get: function () { return SyncLog_1.SyncLog; } });
6
+ Object.defineProperty(exports, "SyncLogAction", { enumerable: true, get: function () { return SyncLog_1.SyncLogAction; } });
7
+ Object.defineProperty(exports, "SyncLogStatus", { enumerable: true, get: function () { return SyncLog_1.SyncLogStatus; } });
8
+ Object.defineProperty(exports, "SyncLogType", { enumerable: true, get: function () { return SyncLog_1.SyncLogType; } });
@@ -0,0 +1,43 @@
1
+ import { Document, Types } from "mongoose";
2
+ /**
3
+ * Sync Log Types
4
+ */
5
+ export declare enum SyncLogType {
6
+ SAP_QUOTATION = "SAP_QUOTATION",
7
+ SAP_SALES_ORDER = "SAP_SALES_ORDER",
8
+ PIPEDRIVE = "PIPEDRIVE"
9
+ }
10
+ export declare enum SyncLogStatus {
11
+ PENDING = "PENDING",
12
+ SUCCESS = "SUCCESS",
13
+ FAILED = "FAILED",
14
+ RETRYING = "RETRYING"
15
+ }
16
+ export declare enum SyncLogAction {
17
+ CREATE = "CREATE",
18
+ UPDATE = "UPDATE",
19
+ DELETE = "DELETE"
20
+ }
21
+ export interface ISyncLog extends Document {
22
+ _id: Types.ObjectId;
23
+ entity_type: string;
24
+ entity_id: Types.ObjectId;
25
+ sync_type: SyncLogType;
26
+ action: SyncLogAction;
27
+ status: SyncLogStatus;
28
+ error_message?: string;
29
+ error_code?: string;
30
+ error_details?: Record<string, any>;
31
+ request_payload?: Record<string, any>;
32
+ response_payload?: Record<string, any>;
33
+ retry_count: number;
34
+ max_retries: number;
35
+ next_retry_at?: Date;
36
+ created_at: Date;
37
+ updated_at: Date;
38
+ resolved_at?: Date;
39
+ resolved_by?: Types.ObjectId;
40
+ }
41
+ export declare const SyncLog: import("mongoose").Model<ISyncLog, {}, {}, {}, Document<unknown, {}, ISyncLog> & ISyncLog & Required<{
42
+ _id: Types.ObjectId;
43
+ }>, any>;
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SyncLog = exports.SyncLogAction = exports.SyncLogStatus = exports.SyncLogType = void 0;
4
+ const mongoose_1 = require("mongoose");
5
+ /**
6
+ * Sync Log Types
7
+ */
8
+ var SyncLogType;
9
+ (function (SyncLogType) {
10
+ SyncLogType["SAP_QUOTATION"] = "SAP_QUOTATION";
11
+ SyncLogType["SAP_SALES_ORDER"] = "SAP_SALES_ORDER";
12
+ SyncLogType["PIPEDRIVE"] = "PIPEDRIVE";
13
+ })(SyncLogType || (exports.SyncLogType = SyncLogType = {}));
14
+ var SyncLogStatus;
15
+ (function (SyncLogStatus) {
16
+ SyncLogStatus["PENDING"] = "PENDING";
17
+ SyncLogStatus["SUCCESS"] = "SUCCESS";
18
+ SyncLogStatus["FAILED"] = "FAILED";
19
+ SyncLogStatus["RETRYING"] = "RETRYING";
20
+ })(SyncLogStatus || (exports.SyncLogStatus = SyncLogStatus = {}));
21
+ var SyncLogAction;
22
+ (function (SyncLogAction) {
23
+ SyncLogAction["CREATE"] = "CREATE";
24
+ SyncLogAction["UPDATE"] = "UPDATE";
25
+ SyncLogAction["DELETE"] = "DELETE";
26
+ })(SyncLogAction || (exports.SyncLogAction = SyncLogAction = {}));
27
+ const syncLogSchema = new mongoose_1.Schema({
28
+ entity_type: {
29
+ type: String,
30
+ required: true,
31
+ index: true,
32
+ },
33
+ entity_id: {
34
+ type: mongoose_1.Schema.Types.ObjectId,
35
+ required: true,
36
+ index: true,
37
+ },
38
+ sync_type: {
39
+ type: String,
40
+ enum: Object.values(SyncLogType),
41
+ required: true,
42
+ index: true,
43
+ },
44
+ action: {
45
+ type: String,
46
+ enum: Object.values(SyncLogAction),
47
+ required: true,
48
+ },
49
+ status: {
50
+ type: String,
51
+ enum: Object.values(SyncLogStatus),
52
+ default: SyncLogStatus.PENDING,
53
+ index: true,
54
+ },
55
+ error_message: { type: String },
56
+ error_code: { type: String },
57
+ error_details: { type: mongoose_1.Schema.Types.Mixed },
58
+ request_payload: { type: mongoose_1.Schema.Types.Mixed },
59
+ response_payload: { type: mongoose_1.Schema.Types.Mixed },
60
+ retry_count: { type: Number, default: 0 },
61
+ max_retries: { type: Number, default: 3 },
62
+ next_retry_at: { type: Date },
63
+ resolved_at: { type: Date },
64
+ resolved_by: { type: mongoose_1.Schema.Types.ObjectId, ref: "User" },
65
+ }, {
66
+ timestamps: { createdAt: "created_at", updatedAt: "updated_at" },
67
+ });
68
+ syncLogSchema.index({ entity_type: 1, entity_id: 1, status: 1 });
69
+ syncLogSchema.index({ status: 1, next_retry_at: 1 });
70
+ exports.SyncLog = (0, mongoose_1.model)("SyncLog", syncLogSchema, "sync_logs");
@@ -0,0 +1 @@
1
+ export { default as Users } from "./models/Users";
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Users = void 0;
7
+ var Users_1 = require("./models/Users");
8
+ Object.defineProperty(exports, "Users", { enumerable: true, get: function () { return __importDefault(Users_1).default; } });
@@ -0,0 +1,36 @@
1
+ import mongoose from "mongoose";
2
+ export declare enum UserRole {
3
+ ADMIN = "admin",
4
+ SALES = "sales",
5
+ TECHNICIAN = "technician",
6
+ WAREHOUSEMAN = "warehouseman"
7
+ }
8
+ export declare enum UserStatus {
9
+ ACTIVE = "active",
10
+ INACTIVE = "inactive",
11
+ SUSPENDED = "suspended"
12
+ }
13
+ export interface UserType {
14
+ first_name: string;
15
+ middle_name?: string;
16
+ last_name: string;
17
+ username: string;
18
+ password: string;
19
+ role: UserRole;
20
+ status: UserStatus;
21
+ email?: string;
22
+ mobile?: string;
23
+ pipedrive_id?: string;
24
+ sap_employee_id?: string;
25
+ sap_id?: string;
26
+ created_at: Date;
27
+ created_by?: mongoose.Types.ObjectId | string;
28
+ updated_at?: Date;
29
+ updated_by?: mongoose.Types.ObjectId;
30
+ deleted_at?: Date;
31
+ deleted_by?: mongoose.Types.ObjectId;
32
+ }
33
+ declare const _default: mongoose.Model<UserType, {}, {}, {}, mongoose.Document<unknown, {}, UserType> & UserType & {
34
+ _id: mongoose.Types.ObjectId;
35
+ }, any>;
36
+ export default _default;
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.UserStatus = exports.UserRole = void 0;
7
+ const mongoose_1 = require("mongoose");
8
+ const bcryptjs_1 = __importDefault(require("bcryptjs"));
9
+ var UserRole;
10
+ (function (UserRole) {
11
+ UserRole["ADMIN"] = "admin";
12
+ UserRole["SALES"] = "sales";
13
+ UserRole["TECHNICIAN"] = "technician";
14
+ UserRole["WAREHOUSEMAN"] = "warehouseman";
15
+ })(UserRole || (exports.UserRole = UserRole = {}));
16
+ var UserStatus;
17
+ (function (UserStatus) {
18
+ UserStatus["ACTIVE"] = "active";
19
+ UserStatus["INACTIVE"] = "inactive";
20
+ UserStatus["SUSPENDED"] = "suspended";
21
+ })(UserStatus || (exports.UserStatus = UserStatus = {}));
22
+ const usersSchema = new mongoose_1.Schema({
23
+ first_name: { type: String, required: true },
24
+ middle_name: { type: String },
25
+ last_name: { type: String, required: true },
26
+ username: { type: String, required: true, unique: true },
27
+ password: { type: String, required: true, select: false },
28
+ role: {
29
+ type: String,
30
+ enum: Object.values(UserRole),
31
+ default: UserRole.SALES,
32
+ },
33
+ status: {
34
+ type: String,
35
+ enum: Object.values(UserStatus),
36
+ default: UserStatus.ACTIVE,
37
+ },
38
+ email: { type: String },
39
+ mobile: { type: String },
40
+ pipedrive_id: { type: String },
41
+ sap_id: { type: String },
42
+ sap_employee_id: { type: String },
43
+ created_at: { type: Date, default: Date.now },
44
+ created_by: { type: mongoose_1.Schema.Types.Mixed, ref: "User" },
45
+ updated_at: { type: Date },
46
+ updated_by: { type: mongoose_1.Schema.Types.ObjectId, ref: "User" },
47
+ deleted_at: { type: Date },
48
+ deleted_by: { type: mongoose_1.Schema.Types.ObjectId, ref: "User" },
49
+ });
50
+ usersSchema.pre("save", async function (next) {
51
+ if (this.isModified("password")) {
52
+ this.password = await bcryptjs_1.default.hash(this.password, 12);
53
+ }
54
+ next();
55
+ });
56
+ exports.default = (0, mongoose_1.model)("User", usersSchema, "users");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fesmex/models",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [
@@ -13,7 +13,10 @@
13
13
  "mongoose": "^7 || ^8"
14
14
  },
15
15
  "devDependencies": {
16
- "typescript": "^5",
17
- "@types/mongoose": "^5"
16
+ "@types/mongoose": "^5",
17
+ "typescript": "^5"
18
+ },
19
+ "dependencies": {
20
+ "bcryptjs": "^3.0.3"
18
21
  }
19
22
  }