@voyantjs/crm 0.1.1 → 0.3.0
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.
- package/dist/routes/accounts.d.ts +1 -1
- package/dist/routes/index.d.ts +2 -2
- package/dist/routes/opportunities.d.ts +1 -1
- package/dist/schema-accounts.d.ts +1175 -0
- package/dist/schema-accounts.d.ts.map +1 -0
- package/dist/schema-accounts.js +112 -0
- package/dist/schema-activities.d.ts +821 -0
- package/dist/schema-activities.d.ts.map +1 -0
- package/dist/schema-activities.js +83 -0
- package/dist/schema-relations.d.ts +81 -0
- package/dist/schema-relations.d.ts.map +1 -0
- package/dist/schema-relations.js +123 -0
- package/dist/schema-sales.d.ts +1392 -0
- package/dist/schema-sales.d.ts.map +1 -0
- package/dist/schema-sales.js +142 -0
- package/dist/schema-shared.d.ts +13 -0
- package/dist/schema-shared.d.ts.map +1 -0
- package/dist/schema-shared.js +63 -0
- package/dist/schema.d.ts +5 -3477
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +5 -515
- package/dist/service/accounts-organizations.d.ts +93 -0
- package/dist/service/accounts-organizations.d.ts.map +1 -0
- package/dist/service/accounts-organizations.js +49 -0
- package/dist/service/accounts-people.d.ts +868 -0
- package/dist/service/accounts-people.d.ts.map +1 -0
- package/dist/service/accounts-people.js +311 -0
- package/dist/service/accounts-shared.d.ts +54 -0
- package/dist/service/accounts-shared.d.ts.map +1 -0
- package/dist/service/accounts-shared.js +152 -0
- package/dist/service/accounts.d.ts +121 -149
- package/dist/service/accounts.d.ts.map +1 -1
- package/dist/service/accounts.js +4 -507
- package/dist/service/index.d.ts +106 -297
- package/dist/service/index.d.ts.map +1 -1
- package/dist/service/opportunities.d.ts +1 -1
- package/package.json +5 -5
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { and, desc, eq, ilike, or, sql } from "drizzle-orm";
|
|
2
|
+
import { organizations } from "../schema.js";
|
|
3
|
+
import { paginate } from "./helpers.js";
|
|
4
|
+
export const organizationAccountsService = {
|
|
5
|
+
async listOrganizations(db, query) {
|
|
6
|
+
const conditions = [];
|
|
7
|
+
if (query.ownerId)
|
|
8
|
+
conditions.push(eq(organizations.ownerId, query.ownerId));
|
|
9
|
+
if (query.relation)
|
|
10
|
+
conditions.push(eq(organizations.relation, query.relation));
|
|
11
|
+
if (query.status)
|
|
12
|
+
conditions.push(eq(organizations.status, query.status));
|
|
13
|
+
if (query.search) {
|
|
14
|
+
const term = `%${query.search}%`;
|
|
15
|
+
conditions.push(or(ilike(organizations.name, term), ilike(organizations.legalName, term), ilike(organizations.website, term)));
|
|
16
|
+
}
|
|
17
|
+
const where = conditions.length ? and(...conditions) : undefined;
|
|
18
|
+
return paginate(db
|
|
19
|
+
.select()
|
|
20
|
+
.from(organizations)
|
|
21
|
+
.where(where)
|
|
22
|
+
.limit(query.limit)
|
|
23
|
+
.offset(query.offset)
|
|
24
|
+
.orderBy(desc(organizations.updatedAt)), db.select({ count: sql `count(*)::int` }).from(organizations).where(where), query.limit, query.offset);
|
|
25
|
+
},
|
|
26
|
+
async getOrganizationById(db, id) {
|
|
27
|
+
const [row] = await db.select().from(organizations).where(eq(organizations.id, id)).limit(1);
|
|
28
|
+
return row ?? null;
|
|
29
|
+
},
|
|
30
|
+
async createOrganization(db, data) {
|
|
31
|
+
const [row] = await db.insert(organizations).values(data).returning();
|
|
32
|
+
return row;
|
|
33
|
+
},
|
|
34
|
+
async updateOrganization(db, id, data) {
|
|
35
|
+
const [row] = await db
|
|
36
|
+
.update(organizations)
|
|
37
|
+
.set({ ...data, updatedAt: new Date() })
|
|
38
|
+
.where(eq(organizations.id, id))
|
|
39
|
+
.returning();
|
|
40
|
+
return row ?? null;
|
|
41
|
+
},
|
|
42
|
+
async deleteOrganization(db, id) {
|
|
43
|
+
const [row] = await db
|
|
44
|
+
.delete(organizations)
|
|
45
|
+
.where(eq(organizations.id, id))
|
|
46
|
+
.returning({ id: organizations.id });
|
|
47
|
+
return row ?? null;
|
|
48
|
+
},
|
|
49
|
+
};
|