@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.
@@ -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;CAmBT"}
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"}
@@ -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 OR = fields.map((field) => ({
27
- [field]: { contains: paginationParams.search },
28
- }));
29
- if (this.isPostgres()) {
30
- OR.forEach((condition) => {
31
- Object.keys(condition).forEach((key) => {
32
- condition[key].mode = 'insensitive';
33
- });
34
- });
35
- }
36
- if (!isNaN(+paginationParams.search)) {
37
- OR.push({ id: { equals: +paginationParams.search } });
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,GAAQ,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;YACrC,CAAC,KAAK,CAAC,EAAE,EAAE,QAAQ,EAAE,gBAAgB,CAAC,MAAM,EAAE;SAC/C,CAAC,CAAC,CAAC;QAEJ,IAAI,IAAI,CAAC,UAAU,EAAE,EAAE,CAAC;YACtB,EAAE,CAAC,OAAO,CAAC,CA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.js",
6
6
  "scripts": {
@@ -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 OR: any = fields.map((field) => ({
27
- [field]: { contains: paginationParams.search },
28
- }));
29
-
30
- if (this.isPostgres()) {
31
- OR.forEach((condition) => {
32
- Object.keys(condition).forEach((key) => {
33
- (condition[key] as any).mode = 'insensitive';
34
- });
35
- });
36
- }
37
-
38
- if (!isNaN(+paginationParams.search)) {
39
- OR.push({ id: { equals: +paginationParams.search } });
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;