@hedhog/prisma 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/prisma.service.d.ts.map +1 -1
- package/dist/prisma.service.js +20 -12
- package/dist/prisma.service.js.map +1 -1
- package/package.json +1 -1
- package/src/prisma.service.ts +26 -14
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"prisma.service.d.ts","sourceRoot":"","sources":["../src/prisma.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,qBACa,aAAc,SAAQ,YAAa,YAAW,YAAY;IAC/D,YAAY;IAIlB,WAAW;IAIX,UAAU;IAIV,OAAO;IAIP,uBAAuB,CACrB,MAAM,EAAE,MAAM,EAAE,EAChB,gBAAgB,EAAE;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,GACnC,GAAG,EAAE;
|
1
|
+
{"version":3,"file":"prisma.service.d.ts","sourceRoot":"","sources":["../src/prisma.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,qBACa,aAAc,SAAQ,YAAa,YAAW,YAAY;IAC/D,YAAY;IAIlB,WAAW;IAIX,UAAU;IAIV,OAAO;IAIP,uBAAuB,CACrB,MAAM,EAAE,MAAM,EAAE,EAChB,gBAAgB,EAAE;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,GACnC,GAAG,EAAE;CA+BT"}
|
package/dist/prisma.service.js
CHANGED
@@ -23,18 +23,26 @@ let PrismaService = class PrismaService extends client_1.PrismaClient {
|
|
23
23
|
return this.getProvider() === 'mysql';
|
24
24
|
}
|
25
25
|
createInsensitiveSearch(fields, paginationParams) {
|
26
|
-
const
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
26
|
+
const searchValue = paginationParams.search;
|
27
|
+
const OR = [];
|
28
|
+
fields.forEach((field) => {
|
29
|
+
if (field === 'id' && !isNaN(+searchValue)) {
|
30
|
+
OR.push({ id: { equals: +searchValue } });
|
31
|
+
}
|
32
|
+
else if (field === 'method' &&
|
33
|
+
['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS', 'HEAD'].includes(searchValue)) {
|
34
|
+
OR.push({ method: { equals: searchValue } });
|
35
|
+
}
|
36
|
+
else if (field !== 'method') {
|
37
|
+
const condition = { [field]: { contains: searchValue } };
|
38
|
+
if (this.isPostgres()) {
|
39
|
+
condition[field].mode = 'insensitive';
|
40
|
+
}
|
41
|
+
OR.push(condition);
|
42
|
+
}
|
43
|
+
});
|
44
|
+
if (!isNaN(+searchValue)) {
|
45
|
+
OR.push({ id: { equals: +searchValue } });
|
38
46
|
}
|
39
47
|
return OR;
|
40
48
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"prisma.service.js","sourceRoot":"","sources":["../src/prisma.service.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAA0D;AAC1D,2CAA8C;AAGvC,IAAM,aAAa,GAAnB,MAAM,aAAc,SAAQ,qBAAY;IAC7C,KAAK,CAAC,YAAY;QAChB,MAAM,IAAI,CAAC,QAAQ,EAAE,CAAC;IACxB,CAAC;IAED,WAAW;QACT,OAAQ,IAAY,CAAC,aAAa,CAAC,cAAc,CAAC;IACpD,CAAC;IAED,UAAU;QACR,OAAO,IAAI,CAAC,WAAW,EAAE,KAAK,YAAY,CAAC;IAC7C,CAAC;IAED,OAAO;QACL,OAAO,IAAI,CAAC,WAAW,EAAE,KAAK,OAAO,CAAC;IACxC,CAAC;IAED,uBAAuB,CACrB,MAAgB,EAChB,gBAAoC;QAEpC,MAAM,EAAE,
|
1
|
+
{"version":3,"file":"prisma.service.js","sourceRoot":"","sources":["../src/prisma.service.ts"],"names":[],"mappings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CAAC,UAAU,EAAE,EAAE,CAAC;oBACrB,SAAS,CAAC,KAAK,CAAS,CAAC,IAAI,GAAG,aAAa,CAAC;gBACjD,CAAC;gBAED,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YACrB,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,KAAK,CAAC,CAAC,WAAW,CAAC,EAAE,CAAC;YACzB,EAAE,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;QAC5C,CAAC;QAED,OAAO,EAAE,CAAC;IACZ,CAAC;CACF,CAAA;AAnDY,sCAAa;wBAAb,aAAa;IADzB,IAAA,mBAAU,GAAE;GACA,aAAa,CAmDzB"}
|
package/package.json
CHANGED
package/src/prisma.service.ts
CHANGED
@@ -23,20 +23,32 @@ export class PrismaService extends PrismaClient implements OnModuleInit {
|
|
23
23
|
fields: string[],
|
24
24
|
paginationParams: { search: string },
|
25
25
|
): any[] {
|
26
|
-
const
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
26
|
+
const searchValue = paginationParams.search;
|
27
|
+
const OR: any[] = [];
|
28
|
+
|
29
|
+
fields.forEach((field) => {
|
30
|
+
if (field === 'id' && !isNaN(+searchValue)) {
|
31
|
+
OR.push({ id: { equals: +searchValue } });
|
32
|
+
} else if (
|
33
|
+
field === 'method' &&
|
34
|
+
['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS', 'HEAD'].includes(
|
35
|
+
searchValue,
|
36
|
+
)
|
37
|
+
) {
|
38
|
+
OR.push({ method: { equals: searchValue } });
|
39
|
+
} else if (field !== 'method') {
|
40
|
+
const condition = { [field]: { contains: searchValue } };
|
41
|
+
|
42
|
+
if (this.isPostgres()) {
|
43
|
+
(condition[field] as any).mode = 'insensitive';
|
44
|
+
}
|
45
|
+
|
46
|
+
OR.push(condition);
|
47
|
+
}
|
48
|
+
});
|
49
|
+
|
50
|
+
if (!isNaN(+searchValue)) {
|
51
|
+
OR.push({ id: { equals: +searchValue } });
|
40
52
|
}
|
41
53
|
|
42
54
|
return OR;
|