@betterinternship/schema 0.16.2 → 1.0.1
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/db.iom.types.d.ts +4 -0
- package/dist/db.js +46 -31
- package/dist/db.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/repository/base.d.ts +50 -0
- package/dist/repository/base.js +345 -0
- package/dist/repository/base.js.map +1 -0
- package/dist/repository/errors.d.ts +1 -0
- package/dist/repository/errors.js +16 -0
- package/dist/repository/errors.js.map +1 -0
- package/dist/repository/factories.d.ts +14 -0
- package/dist/repository/factories.js +45 -0
- package/dist/repository/factories.js.map +1 -0
- package/dist/repository/index.d.ts +3 -0
- package/dist/repository/index.js +20 -0
- package/dist/repository/index.js.map +1 -0
- package/dist/repository/json-columns.d.ts +5 -0
- package/dist/repository/json-columns.js +44 -0
- package/dist/repository/json-columns.js.map +1 -0
- package/dist/repository/paginator.d.ts +4 -0
- package/dist/repository/paginator.js +3 -0
- package/dist/repository/paginator.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
package/dist/db.iom.types.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export type Generated<T> = T extends ColumnType<infer S, infer I, infer U> ? Col
|
|
|
3
3
|
export type IomAuditEventType = "career_nudge_sent" | "company_blacklisted" | "company_invite_accepted" | "company_invite_registered" | "company_invite_sent" | "company_review_approved" | "company_review_rejected" | "company_review_requested" | "company_unblacklisted" | "legacy_document_uploaded" | "legacy_moa_bulk_uploaded" | "legacy_moa_created" | "moa_issued" | "moa_revoked";
|
|
4
4
|
export type IomAuthPurpose = "invite" | "password_reset";
|
|
5
5
|
export type IomAuthSubjectType = "company" | "company_invite" | "university_account";
|
|
6
|
+
export type IomCompanyInviteKind = "listing" | "moa";
|
|
6
7
|
export type IomCompanyInviteStatus = "accepted" | "expired" | "pending" | "used_waiting";
|
|
7
8
|
export type IomCompanyReviewStatus = "approved" | "rejected" | "superseded";
|
|
8
9
|
export type IomCompanyType = "corporation" | "government_agency" | "partnership" | "sole_proprietorship";
|
|
@@ -83,6 +84,8 @@ export interface IomCompanyInvites {
|
|
|
83
84
|
expires_at: Timestamp;
|
|
84
85
|
id: Generated<string>;
|
|
85
86
|
invited_email: string;
|
|
87
|
+
kind: Generated<IomCompanyInviteKind>;
|
|
88
|
+
legacy_company_id: string | null;
|
|
86
89
|
personal_message: string | null;
|
|
87
90
|
status: Generated<IomCompanyInviteStatus>;
|
|
88
91
|
template_id: string | null;
|
|
@@ -117,6 +120,7 @@ export interface IomLegacyCompanies {
|
|
|
117
120
|
created_at: Generated<Timestamp>;
|
|
118
121
|
id: Generated<string>;
|
|
119
122
|
moas: Generated<Json>;
|
|
123
|
+
registered_company_id: string | null;
|
|
120
124
|
university_id: string;
|
|
121
125
|
updated_at: Generated<Timestamp>;
|
|
122
126
|
valid_until: Timestamp | null;
|
package/dist/db.js
CHANGED
|
@@ -4,38 +4,53 @@ exports.handleDBError = exports.iomDb = exports.internalDb = exports.documentDb
|
|
|
4
4
|
const kysely_1 = require("kysely");
|
|
5
5
|
const pg_1 = require("pg");
|
|
6
6
|
const env_1 = require("./env");
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
if (
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
7
|
+
let pool;
|
|
8
|
+
const getPool = () => {
|
|
9
|
+
if (pool)
|
|
10
|
+
return pool;
|
|
11
|
+
const DATABASE_URL = env_1.ENV.DATABASE_URL;
|
|
12
|
+
const DATABASE_CA_CERT = env_1.ENV.DATABASE_CA_CERT;
|
|
13
|
+
if (!DATABASE_URL)
|
|
14
|
+
throw new Error("[ERROR:ENV] Missing DATABASE_URL.");
|
|
15
|
+
const isNoVerify = DATABASE_URL.includes("sslmode=no-verify");
|
|
16
|
+
if (!DATABASE_CA_CERT && !isNoVerify)
|
|
17
|
+
throw new Error("[ERROR:ENV] Missing DATABASE_CA_CERT.");
|
|
18
|
+
pool = new pg_1.Pool({
|
|
19
|
+
connectionString: DATABASE_URL,
|
|
20
|
+
ssl: isNoVerify
|
|
21
|
+
? { rejectUnauthorized: false }
|
|
22
|
+
: {
|
|
23
|
+
rejectUnauthorized: true,
|
|
24
|
+
ca: DATABASE_CA_CERT?.replace(/\\n/g, "\n"),
|
|
25
|
+
checkServerIdentity: () => undefined,
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
return pool;
|
|
29
|
+
};
|
|
30
|
+
const lazyKysely = () => {
|
|
31
|
+
let instance;
|
|
32
|
+
const build = () => (instance ??= new kysely_1.Kysely({
|
|
33
|
+
dialect: new kysely_1.PostgresDialect({ pool: getPool() }),
|
|
34
|
+
}));
|
|
35
|
+
return new Proxy({}, {
|
|
36
|
+
get(_target, prop) {
|
|
37
|
+
const inst = build();
|
|
38
|
+
const value = Reflect.get(inst, prop, inst);
|
|
39
|
+
return typeof value === "function" ? value.bind(inst) : value;
|
|
40
|
+
},
|
|
41
|
+
has(_target, prop) {
|
|
42
|
+
return Reflect.has(build(), prop);
|
|
22
43
|
},
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
exports.documentDb =
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
exports.internalDb = new kysely_1.Kysely({
|
|
34
|
-
dialect: new kysely_1.PostgresDialect({ pool }),
|
|
35
|
-
});
|
|
36
|
-
exports.iomDb = new kysely_1.Kysely({
|
|
37
|
-
dialect: new kysely_1.PostgresDialect({ pool }),
|
|
38
|
-
});
|
|
44
|
+
getPrototypeOf() {
|
|
45
|
+
return Object.getPrototypeOf(build());
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
exports.db = lazyKysely();
|
|
50
|
+
exports.internshipDb = lazyKysely();
|
|
51
|
+
exports.documentDb = lazyKysely();
|
|
52
|
+
exports.internalDb = lazyKysely();
|
|
53
|
+
exports.iomDb = lazyKysely();
|
|
39
54
|
const handleDBError = (error, description = "") => {
|
|
40
55
|
switch (error.code) {
|
|
41
56
|
case "PGRST116":
|
package/dist/db.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"db.js","sourceRoot":"","sources":["../lib/db.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"db.js","sourceRoot":"","sources":["../lib/db.ts"],"names":[],"mappings":";;;AAKA,mCAAiD;AACjD,2BAA0B;AAC1B,+BAA4B;AAa5B,IAAI,IAAsB,CAAC;AAC3B,MAAM,OAAO,GAAG,GAAS,EAAE;IACzB,IAAI,IAAI;QAAE,OAAO,IAAI,CAAC;IAEtB,MAAM,YAAY,GAAG,SAAG,CAAC,YAAY,CAAC;IACtC,MAAM,gBAAgB,GAAG,SAAG,CAAC,gBAAgB,CAAC;IAC9C,IAAI,CAAC,YAAY;QAAE,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;IAGxE,MAAM,UAAU,GAAG,YAAY,CAAC,QAAQ,CAAC,mBAAmB,CAAC,CAAC;IAC9D,IAAI,CAAC,gBAAgB,IAAI,CAAC,UAAU;QAClC,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;IAE3D,IAAI,GAAG,IAAI,SAAI,CAAC;QACd,gBAAgB,EAAE,YAAY;QAC9B,GAAG,EAAE,UAAU;YACb,CAAC,CAAC,EAAE,kBAAkB,EAAE,KAAK,EAAE;YAC/B,CAAC,CAAC;gBACE,kBAAkB,EAAE,IAAI;gBACxB,EAAE,EAAE,gBAAgB,EAAE,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC;gBAE3C,mBAAmB,EAAE,GAAG,EAAE,CAAC,SAAS;aACrC;KACN,CAAC,CAAC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CAAC,WAAW,EAAE,EAAE,KAAK,EAAE,qBAAqB,EAAE,CAAC,CAAC;QACjE,KAAK,OAAO;YACV,MAAM,IAAI,KAAK,CAAC,WAAW,EAAE,EAAE,KAAK,EAAE,0BAA0B,EAAE,CAAC,CAAC;QACtE,KAAK,OAAO;YACV,MAAM,IAAI,KAAK,CAAC,WAAW,EAAE,EAAE,KAAK,EAAE,+BAA+B,EAAE,CAAC,CAAC;QAC3E;YACE,MAAM,IAAI,KAAK,CAAC,WAAW,EAAE,EAAE,KAAK,EAAE,qBAAqB,EAAE,CAAC,CAAC;IACnE,CAAC;AACH,CAAC,CAAC;AAXW,QAAA,aAAa,iBAWxB"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -17,6 +17,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
exports.IOM = exports.Internal = exports.Document = exports.Internship = void 0;
|
|
18
18
|
__exportStar(require("./db"), exports);
|
|
19
19
|
__exportStar(require("./db.types"), exports);
|
|
20
|
+
__exportStar(require("./repository"), exports);
|
|
20
21
|
exports.Internship = require("./db.internship.types");
|
|
21
22
|
exports.Document = require("./db.doc.types");
|
|
22
23
|
exports.Internal = require("./db.internal.types");
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,uCAAqB;AACrB,6CAA2B;AAC3B,sDAAoD;AACpD,6CAA2C;AAC3C,kDAAgD;AAChD,wCAAsC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,uCAAqB;AACrB,6CAA2B;AAC3B,+CAA6B;AAC7B,sDAAoD;AACpD,6CAA2C;AAC3C,kDAAgD;AAChD,wCAAsC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Kysely, Selectable, Insertable, Updateable } from "kysely";
|
|
2
|
+
import { PaginationOptions } from "./paginator";
|
|
3
|
+
export declare class Repository<DB, T extends keyof DB & string, Entity = Selectable<DB[T]>, Insert = Insertable<DB[T]>, Update = Updateable<DB[T]>> {
|
|
4
|
+
protected db: Kysely<DB>;
|
|
5
|
+
protected table: T;
|
|
6
|
+
protected schema: string;
|
|
7
|
+
constructor(db: Kysely<DB>, table: T, schema: string);
|
|
8
|
+
private applySelect;
|
|
9
|
+
private applyCondition;
|
|
10
|
+
private applyFilters;
|
|
11
|
+
findOne(id: string, fields?: string): Promise<Entity>;
|
|
12
|
+
checkOneBy(filter: Partial<{
|
|
13
|
+
[column in keyof DB[T]]: unknown;
|
|
14
|
+
}>, fields?: string): Promise<boolean>;
|
|
15
|
+
countBy(filter?: Partial<{
|
|
16
|
+
[column in keyof DB[T]]: unknown;
|
|
17
|
+
}>): Promise<number>;
|
|
18
|
+
findOneBy(filter: Partial<{
|
|
19
|
+
[column in keyof DB[T]]: unknown;
|
|
20
|
+
}>, fields?: string): Promise<Entity>;
|
|
21
|
+
findLastOrderedBy(filter: Partial<{
|
|
22
|
+
[column in keyof DB[T]]: unknown;
|
|
23
|
+
}>, sortField: keyof DB[T] & string, sortAscending?: boolean, fields?: string): Promise<Entity>;
|
|
24
|
+
findAllBy(filter: Partial<{
|
|
25
|
+
[column in keyof DB[T]]: unknown;
|
|
26
|
+
}>, fields?: string, options?: PaginationOptions): Promise<Entity[]>;
|
|
27
|
+
findAllByOrdered(filter: Partial<{
|
|
28
|
+
[column in keyof DB[T]]: unknown;
|
|
29
|
+
}>, sortField: keyof DB[T] & string, sortAscending?: boolean, options?: PaginationOptions, fields?: string): Promise<Entity[]>;
|
|
30
|
+
findAllIn(filterColumn: keyof DB[T] & string, filterValues: string[], fields?: string): Promise<Entity[]>;
|
|
31
|
+
findAll(fields?: string, options?: PaginationOptions): Promise<Entity[]>;
|
|
32
|
+
findPaginated(filter: Partial<{
|
|
33
|
+
[column in keyof DB[T]]: unknown;
|
|
34
|
+
}>, fields?: string, options?: {
|
|
35
|
+
page?: number;
|
|
36
|
+
limit?: number;
|
|
37
|
+
orderBy?: keyof DB[T] & string;
|
|
38
|
+
orderDir?: "asc" | "desc";
|
|
39
|
+
}): Promise<{
|
|
40
|
+
data: Entity[];
|
|
41
|
+
total: number;
|
|
42
|
+
}>;
|
|
43
|
+
countAll(): Promise<number>;
|
|
44
|
+
insertOne(insert: Partial<Insert>, fields?: string): Promise<Entity>;
|
|
45
|
+
updateOne(id: string, updated: Partial<Update>, fields?: string): Promise<Entity>;
|
|
46
|
+
updateAllBy(filters: Partial<{
|
|
47
|
+
[column in keyof DB[T]]: unknown;
|
|
48
|
+
}>, updated: Partial<Update>, fields?: string): Promise<Entity[]>;
|
|
49
|
+
deleteOne(id: string, fields?: string): Promise<Entity>;
|
|
50
|
+
}
|
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Repository = void 0;
|
|
4
|
+
const json_columns_1 = require("./json-columns");
|
|
5
|
+
const errors_1 = require("./errors");
|
|
6
|
+
const isOperatorObject = (v) => v !== null &&
|
|
7
|
+
typeof v === "object" &&
|
|
8
|
+
!Array.isArray(v) &&
|
|
9
|
+
!(v instanceof Date);
|
|
10
|
+
class Repository {
|
|
11
|
+
db;
|
|
12
|
+
table;
|
|
13
|
+
schema;
|
|
14
|
+
constructor(db, table, schema) {
|
|
15
|
+
this.db = db;
|
|
16
|
+
this.table = table;
|
|
17
|
+
this.schema = schema;
|
|
18
|
+
}
|
|
19
|
+
applySelect(query, fields) {
|
|
20
|
+
if (!fields || fields === "*")
|
|
21
|
+
return query.selectAll();
|
|
22
|
+
const cols = fields.split(",").map((f) => f.trim());
|
|
23
|
+
return query.select(cols);
|
|
24
|
+
}
|
|
25
|
+
applyCondition(query, key, value) {
|
|
26
|
+
const col = key;
|
|
27
|
+
if (value === null) {
|
|
28
|
+
return query.where(col, "is", null);
|
|
29
|
+
}
|
|
30
|
+
if (Array.isArray(value)) {
|
|
31
|
+
return (value.length ? query.where(col, "in", value) : query);
|
|
32
|
+
}
|
|
33
|
+
if (isOperatorObject(value)) {
|
|
34
|
+
let q = query;
|
|
35
|
+
for (const [op, operand] of Object.entries(value)) {
|
|
36
|
+
switch (op) {
|
|
37
|
+
case "gt":
|
|
38
|
+
q = q.where(col, ">", operand);
|
|
39
|
+
break;
|
|
40
|
+
case "gte":
|
|
41
|
+
q = q.where(col, ">=", operand);
|
|
42
|
+
break;
|
|
43
|
+
case "lt":
|
|
44
|
+
q = q.where(col, "<", operand);
|
|
45
|
+
break;
|
|
46
|
+
case "lte":
|
|
47
|
+
q = q.where(col, "<=", operand);
|
|
48
|
+
break;
|
|
49
|
+
case "in":
|
|
50
|
+
if (Array.isArray(operand) && operand.length)
|
|
51
|
+
q = q.where(col, "in", operand);
|
|
52
|
+
break;
|
|
53
|
+
case "not":
|
|
54
|
+
q =
|
|
55
|
+
operand === null
|
|
56
|
+
? q.where(col, "is not", null)
|
|
57
|
+
: q.where(col, "!=", operand);
|
|
58
|
+
break;
|
|
59
|
+
default:
|
|
60
|
+
q = q.where(col, "=", operand);
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return q;
|
|
65
|
+
}
|
|
66
|
+
return query.where(col, "=", value);
|
|
67
|
+
}
|
|
68
|
+
applyFilters(query, filter) {
|
|
69
|
+
let q = query;
|
|
70
|
+
for (const key in filter) {
|
|
71
|
+
q = this.applyCondition(q, key, filter[key]);
|
|
72
|
+
}
|
|
73
|
+
return q;
|
|
74
|
+
}
|
|
75
|
+
async findOne(id, fields) {
|
|
76
|
+
try {
|
|
77
|
+
let query = this.db
|
|
78
|
+
.withSchema(this.schema)
|
|
79
|
+
.selectFrom(this.table)
|
|
80
|
+
.where("id", "=", id);
|
|
81
|
+
query = this.applySelect(query, fields);
|
|
82
|
+
return (await query.executeTakeFirst());
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
return (0, errors_1.logAndHandleDBError)(error, `Could not pull from ${this.table}.`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
async checkOneBy(filter, fields) {
|
|
89
|
+
try {
|
|
90
|
+
let query = this.db
|
|
91
|
+
.withSchema(this.schema)
|
|
92
|
+
.selectFrom(this.table);
|
|
93
|
+
query = this.applyFilters(query, filter);
|
|
94
|
+
query = this.applySelect(query, fields);
|
|
95
|
+
return !!(await query.executeTakeFirst());
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
async countBy(filter = {}) {
|
|
102
|
+
try {
|
|
103
|
+
let query = this.db
|
|
104
|
+
.withSchema(this.schema)
|
|
105
|
+
.selectFrom(this.table);
|
|
106
|
+
query = this.applyFilters(query, filter);
|
|
107
|
+
const result = await query
|
|
108
|
+
.select((eb) => eb.fn.count("id").as("count"))
|
|
109
|
+
.executeTakeFirst();
|
|
110
|
+
return Number(result?.count ?? 0);
|
|
111
|
+
}
|
|
112
|
+
catch {
|
|
113
|
+
return 0;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
async findOneBy(filter, fields) {
|
|
117
|
+
try {
|
|
118
|
+
let query = this.db
|
|
119
|
+
.withSchema(this.schema)
|
|
120
|
+
.selectFrom(this.table);
|
|
121
|
+
query = this.applyFilters(query, filter);
|
|
122
|
+
query = this.applySelect(query, fields);
|
|
123
|
+
return (await query.executeTakeFirst());
|
|
124
|
+
}
|
|
125
|
+
catch (error) {
|
|
126
|
+
return (0, errors_1.logAndHandleDBError)(error, `Could not pull from ${this.table}.`);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
async findLastOrderedBy(filter, sortField, sortAscending = false, fields) {
|
|
130
|
+
try {
|
|
131
|
+
let query = this.db
|
|
132
|
+
.withSchema(this.schema)
|
|
133
|
+
.selectFrom(this.table);
|
|
134
|
+
query = this.applyFilters(query, filter);
|
|
135
|
+
query = this.applySelect(query, fields);
|
|
136
|
+
const data = (await query
|
|
137
|
+
.orderBy(sortField, sortAscending ? "asc" : "desc")
|
|
138
|
+
.limit(1)
|
|
139
|
+
.executeTakeFirst());
|
|
140
|
+
return data ?? null;
|
|
141
|
+
}
|
|
142
|
+
catch (error) {
|
|
143
|
+
return (0, errors_1.logAndHandleDBError)(error, `Could not pull from ${this.table}.`);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
async findAllBy(filter, fields, options) {
|
|
147
|
+
try {
|
|
148
|
+
let query = this.db
|
|
149
|
+
.withSchema(this.schema)
|
|
150
|
+
.selectFrom(this.table);
|
|
151
|
+
query = this.applyFilters(query, filter);
|
|
152
|
+
query = this.applySelect(query, fields);
|
|
153
|
+
if (options?.limit)
|
|
154
|
+
query = query.limit(options.limit);
|
|
155
|
+
if (options?.offset)
|
|
156
|
+
query = query.offset(options.offset);
|
|
157
|
+
return (await query.execute());
|
|
158
|
+
}
|
|
159
|
+
catch (error) {
|
|
160
|
+
return (0, errors_1.logAndHandleDBError)(error, `Could not pull from ${this.table}.`);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
async findAllByOrdered(filter, sortField, sortAscending = false, options, fields) {
|
|
164
|
+
try {
|
|
165
|
+
let query = this.db
|
|
166
|
+
.withSchema(this.schema)
|
|
167
|
+
.selectFrom(this.table);
|
|
168
|
+
query = this.applyFilters(query, filter);
|
|
169
|
+
query = this.applySelect(query, fields);
|
|
170
|
+
query = query.orderBy(sortField, sortAscending ? "asc" : "desc");
|
|
171
|
+
if (options?.limit)
|
|
172
|
+
query = query.limit(options.limit);
|
|
173
|
+
if (options?.offset)
|
|
174
|
+
query = query.offset(options.offset);
|
|
175
|
+
return (await query.execute());
|
|
176
|
+
}
|
|
177
|
+
catch (error) {
|
|
178
|
+
return (0, errors_1.logAndHandleDBError)(error, `Could not pull from ${this.table}.`);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
async findAllIn(filterColumn, filterValues, fields) {
|
|
182
|
+
try {
|
|
183
|
+
if (!filterValues.length)
|
|
184
|
+
return [];
|
|
185
|
+
let query = this.db
|
|
186
|
+
.withSchema(this.schema)
|
|
187
|
+
.selectFrom(this.table);
|
|
188
|
+
query = query.where(filterColumn, "in", filterValues);
|
|
189
|
+
query = this.applySelect(query, fields);
|
|
190
|
+
return (await query.execute());
|
|
191
|
+
}
|
|
192
|
+
catch (error) {
|
|
193
|
+
return (0, errors_1.logAndHandleDBError)(error, `Could not pull from ${this.table}.`);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
async findAll(fields, options) {
|
|
197
|
+
try {
|
|
198
|
+
let query = this.db
|
|
199
|
+
.withSchema(this.schema)
|
|
200
|
+
.selectFrom(this.table);
|
|
201
|
+
query = this.applySelect(query, fields);
|
|
202
|
+
if (options?.limit)
|
|
203
|
+
query = query.limit(options.limit);
|
|
204
|
+
if (options?.offset)
|
|
205
|
+
query = query.offset(options.offset);
|
|
206
|
+
return (await query.execute());
|
|
207
|
+
}
|
|
208
|
+
catch (error) {
|
|
209
|
+
return (0, errors_1.logAndHandleDBError)(error, `Could not pull from ${this.table}.`);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
async findPaginated(filter, fields, options) {
|
|
213
|
+
try {
|
|
214
|
+
const page = options?.page ?? 1;
|
|
215
|
+
const limit = options?.limit ?? 20;
|
|
216
|
+
const offset = (page - 1) * limit;
|
|
217
|
+
const orderBy = options?.orderBy ?? "id";
|
|
218
|
+
const orderDir = options?.orderDir ?? "asc";
|
|
219
|
+
let query = this.db
|
|
220
|
+
.withSchema(this.schema)
|
|
221
|
+
.selectFrom(this.table);
|
|
222
|
+
query = this.applyFilters(query, filter);
|
|
223
|
+
query = this.applySelect(query, fields);
|
|
224
|
+
let countQuery = this.db
|
|
225
|
+
.withSchema(this.schema)
|
|
226
|
+
.selectFrom(this.table)
|
|
227
|
+
.select((eb) => eb.fn.countAll().as("count"));
|
|
228
|
+
countQuery = this.applyFilters(countQuery, filter);
|
|
229
|
+
const [data, countResult] = await Promise.all([
|
|
230
|
+
query.orderBy(orderBy, orderDir).limit(limit).offset(offset).execute(),
|
|
231
|
+
countQuery.executeTakeFirst(),
|
|
232
|
+
]);
|
|
233
|
+
return {
|
|
234
|
+
data: data,
|
|
235
|
+
total: Number(countResult?.count ?? 0),
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
catch (error) {
|
|
239
|
+
return (0, errors_1.logAndHandleDBError)(error, `Could not pull from ${this.table}.`);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
async countAll() {
|
|
243
|
+
try {
|
|
244
|
+
const result = await this.db
|
|
245
|
+
.withSchema(this.schema)
|
|
246
|
+
.selectFrom(this.table)
|
|
247
|
+
.select((eb) => eb.fn.countAll().as("count"))
|
|
248
|
+
.executeTakeFirst();
|
|
249
|
+
return Number(result?.count ?? 0);
|
|
250
|
+
}
|
|
251
|
+
catch {
|
|
252
|
+
return 0;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
async insertOne(insert, fields) {
|
|
256
|
+
try {
|
|
257
|
+
const jsonCols = await (0, json_columns_1.loadJsonColumnMap)(this.db);
|
|
258
|
+
insert = (0, json_columns_1.wrapJsonColumns)(insert, this.table, jsonCols);
|
|
259
|
+
const query = this.db
|
|
260
|
+
.withSchema(this.schema)
|
|
261
|
+
.insertInto(this.table)
|
|
262
|
+
.values(insert);
|
|
263
|
+
if (!fields || fields === "*") {
|
|
264
|
+
return (await query.returningAll().executeTakeFirstOrThrow());
|
|
265
|
+
}
|
|
266
|
+
else {
|
|
267
|
+
const cols = fields.split(",").map((f) => f.trim());
|
|
268
|
+
return (await query
|
|
269
|
+
.returning(cols)
|
|
270
|
+
.executeTakeFirstOrThrow());
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
catch (error) {
|
|
274
|
+
return (0, errors_1.logAndHandleDBError)(error, `Could not insert into ${this.table}.`);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
async updateOne(id, updated, fields) {
|
|
278
|
+
try {
|
|
279
|
+
const jsonCols = await (0, json_columns_1.loadJsonColumnMap)(this.db);
|
|
280
|
+
updated = (0, json_columns_1.wrapJsonColumns)(updated, this.table, jsonCols);
|
|
281
|
+
const query = this.db
|
|
282
|
+
.withSchema(this.schema)
|
|
283
|
+
.updateTable(this.table)
|
|
284
|
+
.set(updated)
|
|
285
|
+
.where("id", "=", id);
|
|
286
|
+
if (!fields || fields === "*") {
|
|
287
|
+
return (await query.returningAll().executeTakeFirstOrThrow());
|
|
288
|
+
}
|
|
289
|
+
else {
|
|
290
|
+
const cols = fields.split(",").map((f) => f.trim());
|
|
291
|
+
return (await query
|
|
292
|
+
.returning(cols)
|
|
293
|
+
.executeTakeFirstOrThrow());
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
catch (error) {
|
|
297
|
+
return (0, errors_1.logAndHandleDBError)(error, `Could not update ${this.table}.`);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
async updateAllBy(filters, updated, fields) {
|
|
301
|
+
if (!Object.entries(filters).length)
|
|
302
|
+
throw new Error("Illegal filters for updateAllBy().");
|
|
303
|
+
try {
|
|
304
|
+
const jsonCols = await (0, json_columns_1.loadJsonColumnMap)(this.db);
|
|
305
|
+
updated = (0, json_columns_1.wrapJsonColumns)(updated, this.table, jsonCols);
|
|
306
|
+
let query = this.db
|
|
307
|
+
.withSchema(this.schema)
|
|
308
|
+
.updateTable(this.table)
|
|
309
|
+
.set(updated);
|
|
310
|
+
query = this.applyFilters(query, filters);
|
|
311
|
+
if (!fields || fields === "*") {
|
|
312
|
+
return (await query.returningAll().execute());
|
|
313
|
+
}
|
|
314
|
+
else {
|
|
315
|
+
const cols = fields.split(",").map((f) => f.trim());
|
|
316
|
+
return (await query.returning(cols).execute());
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
catch (error) {
|
|
320
|
+
return (0, errors_1.logAndHandleDBError)(error, `Could not update ${this.table}.`);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
async deleteOne(id, fields) {
|
|
324
|
+
try {
|
|
325
|
+
const query = this.db
|
|
326
|
+
.withSchema(this.schema)
|
|
327
|
+
.deleteFrom(this.table)
|
|
328
|
+
.where("id", "=", id);
|
|
329
|
+
if (!fields || fields === "*") {
|
|
330
|
+
return (await query.returningAll().executeTakeFirstOrThrow());
|
|
331
|
+
}
|
|
332
|
+
else {
|
|
333
|
+
const cols = fields.split(",").map((f) => f.trim());
|
|
334
|
+
return (await query
|
|
335
|
+
.returning(cols)
|
|
336
|
+
.executeTakeFirstOrThrow());
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
catch (error) {
|
|
340
|
+
return (0, errors_1.logAndHandleDBError)(error, `Could not delete from ${this.table}.`);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
exports.Repository = Repository;
|
|
345
|
+
//# sourceMappingURL=base.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../lib/repository/base.ts"],"names":[],"mappings":";;;AAgBA,iDAAoE;AACpE,qCAAgE;AAWhE,MAAM,gBAAgB,GAAG,CAAC,CAAU,EAAgC,EAAE,CACpE,CAAC,KAAK,IAAI;IACV,OAAO,CAAC,KAAK,QAAQ;IACrB,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;IACjB,CAAC,CAAC,CAAC,YAAY,IAAI,CAAC,CAAC;AASvB,MAAa,UAAU;IAOX,EAAE,CAAa;IACf,KAAK,CAAI;IACT,MAAM,CAAS;IAEzB,YAAY,EAAc,EAAE,KAAQ,EAAE,MAAc;QAClD,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAKO,WAAW,CAAC,KA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,KAAK,EAAE,CAAC;YACf,OAAO,IAAA,4BAAa,EAAC,KAAK,EAAE,oBAAoB,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC;QACjE,CAAC;IACH,CAAC;IAKD,KAAK,CAAC,SAAS,CAAC,EAAU,EAAE,MAAe;QACzC,IAAI,CAAC;YACH,MAAM,KAAK,GAAI,IAAI,CAAC,EAA+B;iBAChD,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC;iBACvB,UAAU,CAAC,IAAI,CAAC,KAAe,CAAC;iBAChC,KAAK,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC;YAExB,IAAI,CAAC,MAAM,IAAI,MAAM,KAAK,GAAG,EAAE,CAAC;gBAC9B,OAAO,CAAC,MAAM,KAAK,CAAC,YAAY,EAAE,CAAC,uBAAuB,EAAE,CAAW,CAAC;YAC1E,CAAC;iBAAM,CAAC;gBACN,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;gBACpD,OAAO,CAAC,MAAM,KAAK;qBAChB,SAAS,CAAC,IAAI,CAAC;qBACf,uBAAuB,EAAE,CAAW,CAAC;YAC1C,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,IAAA,4BAAa,EAAC,KAAK,EAAE,yBAAyB,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC;QACtE,CAAC;IACH,CAAC;CACF;AApfD,gCAofC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const logAndHandleDBError: (error: unknown, description?: string) => never;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.logAndHandleDBError = void 0;
|
|
4
|
+
const db_1 = require("../db");
|
|
5
|
+
const logAndHandleDBError = (error, description) => {
|
|
6
|
+
const e = error;
|
|
7
|
+
console.log(description);
|
|
8
|
+
console.log("details:", e?.details);
|
|
9
|
+
console.log("message:", e?.message);
|
|
10
|
+
console.log("code:", e?.code);
|
|
11
|
+
console.log(e?.stack);
|
|
12
|
+
console.log("=================");
|
|
13
|
+
return (0, db_1.handleDBError)(error, description);
|
|
14
|
+
};
|
|
15
|
+
exports.logAndHandleDBError = logAndHandleDBError;
|
|
16
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../lib/repository/errors.ts"],"names":[],"mappings":";;;AAAA,8BAAsC;AAO/B,MAAM,mBAAmB,GAAG,CACjC,KAAc,EACd,WAAoB,EACb,EAAE;IACT,MAAM,CAAC,GAAG,KAGG,CAAC;IACd,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IACzB,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC;IACpC,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC;IACpC,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC;IAC9B,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;IACtB,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;IACjC,OAAO,IAAA,kBAAa,EAAC,KAAK,EAAE,WAAW,CAAC,CAAC;AAC3C,CAAC,CAAC;AAfW,QAAA,mBAAmB,uBAe9B"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Insertable, Selectable, Updateable } from "kysely";
|
|
2
|
+
import { DocumentDB, InternalDB, InternshipDB, IomDB } from "../db";
|
|
3
|
+
import { DB } from "../db.types";
|
|
4
|
+
import { Repository } from "./base";
|
|
5
|
+
export type CareerTable = keyof DB & string;
|
|
6
|
+
export type InternshipTable = keyof InternshipDB & string;
|
|
7
|
+
export type DocumentTable = keyof DocumentDB & string;
|
|
8
|
+
export type InternalTable = keyof InternalDB & string;
|
|
9
|
+
export type IomTable = keyof IomDB & string;
|
|
10
|
+
export declare function createCareerRepository<Table extends CareerTable, Entity = Selectable<DB[Table]>>(table: Table): new () => Repository<DB, Table, Entity, Insertable<Entity>, Updateable<Entity>>;
|
|
11
|
+
export declare function createInternshipFormsRepository<Table extends InternshipTable>(table: Table): new () => Repository<InternshipDB, Table>;
|
|
12
|
+
export declare function createDocumentRepository<Table extends DocumentTable>(table: Table): new () => Repository<DocumentDB, Table>;
|
|
13
|
+
export declare function createInternalRepository<Table extends InternalTable>(table: Table): new () => Repository<InternalDB, Table>;
|
|
14
|
+
export declare function createIomRepository<Table extends IomTable>(table: Table): new () => Repository<IomDB, Table>;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createCareerRepository = createCareerRepository;
|
|
4
|
+
exports.createInternshipFormsRepository = createInternshipFormsRepository;
|
|
5
|
+
exports.createDocumentRepository = createDocumentRepository;
|
|
6
|
+
exports.createInternalRepository = createInternalRepository;
|
|
7
|
+
exports.createIomRepository = createIomRepository;
|
|
8
|
+
const db_1 = require("../db");
|
|
9
|
+
const base_1 = require("./base");
|
|
10
|
+
function createCareerRepository(table) {
|
|
11
|
+
return class R extends base_1.Repository {
|
|
12
|
+
constructor() {
|
|
13
|
+
super(db_1.db, table, "career");
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
function createInternshipFormsRepository(table) {
|
|
18
|
+
return class R extends base_1.Repository {
|
|
19
|
+
constructor() {
|
|
20
|
+
super(db_1.internshipDb, table, "forms");
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function createDocumentRepository(table) {
|
|
25
|
+
return class R extends base_1.Repository {
|
|
26
|
+
constructor() {
|
|
27
|
+
super(db_1.documentDb, table, "documents");
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
function createInternalRepository(table) {
|
|
32
|
+
return class R extends base_1.Repository {
|
|
33
|
+
constructor() {
|
|
34
|
+
super(db_1.internalDb, table, "internal");
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function createIomRepository(table) {
|
|
39
|
+
return class R extends base_1.Repository {
|
|
40
|
+
constructor() {
|
|
41
|
+
super(db_1.iomDb, table, "iom");
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=factories.js.map
|