This commit is contained in:
phaichayon
2026-06-22 15:49:31 +07:00
parent 1b901efc51
commit 3f28fde39f
36 changed files with 2602 additions and 56 deletions

View File

@@ -213,6 +213,9 @@ export const crmCustomers = pgTable(
leadChannel: text('lead_channel'),
customerGroup: text('customer_group'),
customerSubGroup: text('customer_sub_group'),
ownerUserId: text('owner_user_id'),
ownerAssignedAt: timestamp('owner_assigned_at', { withTimezone: true }),
ownerAssignedBy: text('owner_assigned_by'),
notes: text('notes'),
isActive: boolean('is_active').default(true).notNull(),
createdAt: timestamp('created_at', { withTimezone: true }).defaultNow().notNull(),
@@ -229,6 +232,20 @@ export const crmCustomers = pgTable(
})
);
export const crmCustomerOwnerHistory = pgTable('crm_customer_owner_history', {
id: text('id').primaryKey(),
organizationId: text('organization_id').notNull(),
customerId: text('customer_id').notNull(),
oldOwnerUserId: text('old_owner_user_id'),
newOwnerUserId: text('new_owner_user_id'),
changedBy: text('changed_by').notNull(),
changedAt: timestamp('changed_at', { withTimezone: true }).defaultNow().notNull(),
remark: text('remark'),
createdAt: timestamp('created_at', { withTimezone: true }).defaultNow().notNull(),
updatedAt: timestamp('updated_at', { withTimezone: true }).defaultNow().notNull(),
deletedAt: timestamp('deleted_at', { withTimezone: true })
});
export const crmCustomerContacts = pgTable('crm_customer_contacts', {
id: text('id').primaryKey(),
organizationId: text('organization_id').notNull(),
@@ -249,6 +266,30 @@ export const crmCustomerContacts = pgTable('crm_customer_contacts', {
updatedBy: text('updated_by').notNull()
});
export const crmContactShares = pgTable(
'crm_contact_shares',
{
id: text('id').primaryKey(),
organizationId: text('organization_id').notNull(),
contactId: text('contact_id').notNull(),
sharedToUserId: text('shared_to_user_id').notNull(),
sharedByUserId: text('shared_by_user_id').notNull(),
sharedAt: timestamp('shared_at', { withTimezone: true }).defaultNow().notNull(),
isActive: boolean('is_active').default(true).notNull(),
remark: text('remark'),
createdAt: timestamp('created_at', { withTimezone: true }).defaultNow().notNull(),
updatedAt: timestamp('updated_at', { withTimezone: true }).defaultNow().notNull(),
deletedAt: timestamp('deleted_at', { withTimezone: true })
},
(table) => ({
contactSharedUserIdx: uniqueIndex('crm_contact_shares_org_contact_shared_user_idx').on(
table.organizationId,
table.contactId,
table.sharedToUserId
)
})
);
export const crmEnquiries = pgTable(
'crm_enquiries',
{