brackets-prisma-db 2.1.0 → 2.1.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.
Files changed (83) hide show
  1. package/README.md +15 -24
  2. package/dist/prisma-id.d.ts +10 -0
  3. package/dist/prisma-id.js +32 -0
  4. package/dist/storage-handlers/delete-handlers/group.d.ts +1 -1
  5. package/dist/storage-handlers/delete-handlers/group.js +24 -15
  6. package/dist/storage-handlers/delete-handlers/match-game.d.ts +1 -1
  7. package/dist/storage-handlers/delete-handlers/match-game.js +25 -16
  8. package/dist/storage-handlers/delete-handlers/match.d.ts +1 -1
  9. package/dist/storage-handlers/delete-handlers/match.js +26 -17
  10. package/dist/storage-handlers/delete-handlers/participant.d.ts +1 -1
  11. package/dist/storage-handlers/delete-handlers/participant.js +24 -15
  12. package/dist/storage-handlers/delete-handlers/round.d.ts +1 -1
  13. package/dist/storage-handlers/delete-handlers/round.js +25 -16
  14. package/dist/storage-handlers/delete-handlers/stage.d.ts +1 -1
  15. package/dist/storage-handlers/delete-handlers/stage.js +32 -29
  16. package/dist/storage-handlers/delete.d.ts +1 -1
  17. package/dist/storage-handlers/delete.js +1 -2
  18. package/dist/storage-handlers/insert-handlers/group.d.ts +2 -2
  19. package/dist/storage-handlers/insert-handlers/group.js +16 -16
  20. package/dist/storage-handlers/insert-handlers/match-game.d.ts +2 -2
  21. package/dist/storage-handlers/insert-handlers/match-game.js +19 -18
  22. package/dist/storage-handlers/insert-handlers/match.d.ts +2 -2
  23. package/dist/storage-handlers/insert-handlers/match.js +19 -18
  24. package/dist/storage-handlers/insert-handlers/participant.d.ts +2 -2
  25. package/dist/storage-handlers/insert-handlers/participant.js +20 -20
  26. package/dist/storage-handlers/insert-handlers/round.d.ts +2 -2
  27. package/dist/storage-handlers/insert-handlers/round.js +16 -16
  28. package/dist/storage-handlers/insert-handlers/stage.d.ts +2 -2
  29. package/dist/storage-handlers/insert-handlers/stage.js +26 -26
  30. package/dist/storage-handlers/insert.d.ts +1 -1
  31. package/dist/storage-handlers/insert.js +1 -2
  32. package/dist/storage-handlers/select-handlers/group.d.ts +2 -2
  33. package/dist/storage-handlers/select-handlers/group.js +34 -28
  34. package/dist/storage-handlers/select-handlers/match-game.d.ts +2 -1
  35. package/dist/storage-handlers/select-handlers/match-game.js +49 -42
  36. package/dist/storage-handlers/select-handlers/match.d.ts +2 -1
  37. package/dist/storage-handlers/select-handlers/match.js +59 -52
  38. package/dist/storage-handlers/select-handlers/participant.d.ts +2 -2
  39. package/dist/storage-handlers/select-handlers/participant.js +31 -24
  40. package/dist/storage-handlers/select-handlers/round.d.ts +2 -2
  41. package/dist/storage-handlers/select-handlers/round.js +35 -28
  42. package/dist/storage-handlers/select-handlers/stage.d.ts +2 -2
  43. package/dist/storage-handlers/select-handlers/stage.js +54 -47
  44. package/dist/storage-handlers/select.d.ts +2 -2
  45. package/dist/storage-handlers/select.js +1 -2
  46. package/dist/storage-handlers/update-handlers/group.d.ts +2 -2
  47. package/dist/storage-handlers/update-handlers/group.js +31 -25
  48. package/dist/storage-handlers/update-handlers/match-game.d.ts +2 -1
  49. package/dist/storage-handlers/update-handlers/match-game.js +12 -12
  50. package/dist/storage-handlers/update-handlers/match.d.ts +2 -1
  51. package/dist/storage-handlers/update-handlers/match.js +14 -14
  52. package/dist/storage-handlers/update-handlers/participant.d.ts +2 -2
  53. package/dist/storage-handlers/update-handlers/participant.js +32 -26
  54. package/dist/storage-handlers/update-handlers/round.d.ts +2 -2
  55. package/dist/storage-handlers/update-handlers/round.js +34 -28
  56. package/dist/storage-handlers/update-handlers/stage.d.ts +2 -2
  57. package/dist/storage-handlers/update-handlers/stage.js +46 -43
  58. package/dist/storage-handlers/update.d.ts +2 -2
  59. package/dist/storage-handlers/update.js +1 -2
  60. package/dist/storage.d.ts +3 -4
  61. package/dist/transformers/enum/grand-final-type.js +17 -7
  62. package/dist/transformers/enum/match-result.js +17 -7
  63. package/dist/transformers/enum/match-status.d.ts +1 -1
  64. package/dist/transformers/enum/match-status.js +21 -7
  65. package/dist/transformers/enum/round-robin-mode.js +17 -7
  66. package/dist/transformers/enum/seed-ordering.js +17 -7
  67. package/dist/transformers/enum/stage-type.js +17 -7
  68. package/dist/transformers/model/group.d.ts +1 -1
  69. package/dist/transformers/model/group.js +2 -1
  70. package/dist/transformers/model/match-game.d.ts +3 -3
  71. package/dist/transformers/model/match-game.js +5 -4
  72. package/dist/transformers/model/match.d.ts +3 -3
  73. package/dist/transformers/model/match.js +6 -5
  74. package/dist/transformers/model/participant-result.d.ts +1 -1
  75. package/dist/transformers/model/participant.d.ts +3 -3
  76. package/dist/transformers/model/participant.js +4 -3
  77. package/dist/transformers/model/round.d.ts +1 -1
  78. package/dist/transformers/model/round.js +3 -2
  79. package/dist/transformers/model/stage-settings.d.ts +2 -2
  80. package/dist/transformers/model/stage.d.ts +2 -2
  81. package/dist/transformers/model/stage.js +2 -1
  82. package/dist/types.d.ts +1 -1
  83. package/package.json +5 -5
@@ -1,42 +1,49 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.handleRoundSelect = void 0;
3
+ exports.handleRoundSelect = handleRoundSelect;
4
4
  const transformers_1 = require("../../transformers");
5
+ const prisma_id_1 = require("../../prisma-id");
5
6
  async function handleRoundSelect(prisma, filter) {
6
7
  if (filter === undefined) {
7
8
  // Query all entries of table
8
- return prisma.round
9
- .findMany({
10
- orderBy: [{ number: 'asc' }],
11
- })
12
- .then((values) => values.map(transformers_1.RoundTransformer.from))
13
- .catch(() => []);
9
+ try {
10
+ const values = await prisma.round.findMany({
11
+ orderBy: [{ number: 'asc' }],
12
+ });
13
+ return values.map(transformers_1.RoundTransformer.from);
14
+ }
15
+ catch {
16
+ return [];
17
+ }
14
18
  }
15
- if (typeof filter === 'number') {
19
+ if ((0, prisma_id_1.isModelId)(filter)) {
16
20
  // Find by Id
17
- return prisma.round
18
- .findFirst({
19
- where: { id: filter },
20
- })
21
- .then((value) => {
21
+ try {
22
+ const value = await prisma.round.findFirst({
23
+ where: { id: (0, prisma_id_1.toPrismaId)(filter) },
24
+ });
22
25
  if (value === null) {
23
26
  return null;
24
27
  }
25
28
  return transformers_1.RoundTransformer.from(value);
26
- })
27
- .catch(() => null);
29
+ }
30
+ catch {
31
+ return null;
32
+ }
33
+ }
34
+ try {
35
+ const values = await prisma.round.findMany({
36
+ where: {
37
+ id: (0, prisma_id_1.toPrismaId)(filter.id),
38
+ stageId: (0, prisma_id_1.toPrismaId)(filter.stage_id),
39
+ groupId: (0, prisma_id_1.toPrismaId)(filter.group_id),
40
+ number: filter.number,
41
+ },
42
+ orderBy: [{ number: 'asc' }],
43
+ });
44
+ return values.map(transformers_1.RoundTransformer.from);
45
+ }
46
+ catch {
47
+ return [];
28
48
  }
29
- return prisma.round
30
- .findMany({
31
- where: {
32
- id: filter.id,
33
- stageId: filter.stage_id,
34
- groupId: filter.group_id,
35
- number: filter.number,
36
- },
37
- orderBy: [{ number: 'asc' }],
38
- })
39
- .then((values) => values.map(transformers_1.RoundTransformer.from))
40
- .catch(() => []);
41
49
  }
42
- exports.handleRoundSelect = handleRoundSelect;
@@ -1,3 +1,3 @@
1
- import { DataTypes } from 'brackets-manager/dist/types';
1
+ import { DataTypes, Id } from 'brackets-model';
2
2
  import { PrismaClient } from '@prisma/client';
3
- export declare function handleStageSelect(prisma: PrismaClient, filter?: Partial<DataTypes['stage']> | number): Promise<DataTypes['stage'][] | DataTypes['stage'] | null>;
3
+ export declare function handleStageSelect(prisma: PrismaClient, filter?: Partial<DataTypes['stage']> | Id): Promise<DataTypes['stage'][] | DataTypes['stage'] | null>;
@@ -1,67 +1,74 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.handleStageSelect = void 0;
3
+ exports.handleStageSelect = handleStageSelect;
4
4
  const transformers_1 = require("../../transformers");
5
+ const prisma_id_1 = require("../../prisma-id");
5
6
  async function handleStageSelect(prisma, filter) {
6
7
  if (filter === undefined) {
7
8
  // Query all entries of table
8
- return prisma.stage
9
- .findMany({
10
- include: {
11
- settings: true,
12
- },
13
- orderBy: [{ number: 'asc' }],
14
- })
15
- .then((values) => values.map((value) => {
9
+ try {
10
+ const values = await prisma.stage.findMany({
11
+ include: {
12
+ settings: true,
13
+ },
14
+ orderBy: [{ number: 'asc' }],
15
+ });
16
+ return values.map((value) => {
17
+ if (value.settings === null) {
18
+ throw Error(`Stage didn't have a Settings Relation attached.`);
19
+ }
20
+ return transformers_1.StageTransformer.from(value);
21
+ });
22
+ }
23
+ catch {
24
+ return [];
25
+ }
26
+ }
27
+ if ((0, prisma_id_1.isModelId)(filter)) {
28
+ // Find by Id
29
+ try {
30
+ const value = await prisma.stage.findFirst({
31
+ where: { id: (0, prisma_id_1.toPrismaId)(filter) },
32
+ include: {
33
+ settings: true,
34
+ },
35
+ });
36
+ if (value === null) {
37
+ return null;
38
+ }
16
39
  if (value.settings === null) {
17
40
  throw Error(`Stage didn't have a Settings Relation attached.`);
18
41
  }
19
42
  return transformers_1.StageTransformer.from(value);
20
- }))
21
- .catch(() => []);
43
+ }
44
+ catch {
45
+ return null;
46
+ }
22
47
  }
23
- if (typeof filter === 'number') {
24
- // Find by Id
25
- return prisma.stage
26
- .findFirst({
27
- where: { id: filter },
48
+ try {
49
+ const values = await prisma.stage.findMany({
50
+ where: {
51
+ id: (0, prisma_id_1.toPrismaId)(filter.id),
52
+ name: filter.name,
53
+ tournamentId: (0, prisma_id_1.toPrismaId)(filter.tournament_id),
54
+ number: filter.number,
55
+ type: filter.type
56
+ ? transformers_1.StageTypeTransformer.to(filter.type)
57
+ : undefined,
58
+ },
28
59
  include: {
29
60
  settings: true,
30
61
  },
31
- })
32
- .then((value) => {
33
- if (value === null) {
34
- return null;
35
- }
62
+ orderBy: [{ number: 'asc' }],
63
+ });
64
+ return values.map((value) => {
36
65
  if (value.settings === null) {
37
66
  throw Error(`Stage didn't have a Settings Relation attached.`);
38
67
  }
39
68
  return transformers_1.StageTransformer.from(value);
40
- })
41
- .catch(() => null);
69
+ });
70
+ }
71
+ catch {
72
+ return [];
42
73
  }
43
- return prisma.stage
44
- .findMany({
45
- where: {
46
- id: filter.id,
47
- name: filter.name,
48
- tournamentId: filter.tournament_id,
49
- number: filter.number,
50
- type: filter.type
51
- ? transformers_1.StageTypeTransformer.to(filter.type)
52
- : undefined,
53
- },
54
- include: {
55
- settings: true,
56
- },
57
- orderBy: [{ number: 'asc' }],
58
- })
59
- .then((values) => values.map((value) => {
60
- if (value.settings === null) {
61
- throw Error(`Stage didn't have a Settings Relation attached.`);
62
- }
63
- return transformers_1.StageTransformer.from(value);
64
- }))
65
- .catch(() => []);
66
74
  }
67
- exports.handleStageSelect = handleStageSelect;
@@ -1,3 +1,3 @@
1
- import { DataTypes } from 'brackets-manager/dist/types';
1
+ import { DataTypes, Id } from 'brackets-model';
2
2
  import { PrismaClient } from '@prisma/client';
3
- export declare function handleSelect<T extends keyof DataTypes>(prisma: PrismaClient, table: T, filter?: Partial<DataTypes[T]> | number): Promise<DataTypes[T][] | DataTypes[T] | null>;
3
+ export declare function handleSelect<T extends keyof DataTypes>(prisma: PrismaClient, table: T, filter?: Partial<DataTypes[T]> | Id): Promise<DataTypes[T][] | DataTypes[T] | null>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.handleSelect = void 0;
3
+ exports.handleSelect = handleSelect;
4
4
  const select_handlers_1 = require("./select-handlers");
5
5
  async function handleSelect(prisma, table, filter) {
6
6
  switch (table) {
@@ -20,4 +20,3 @@ async function handleSelect(prisma, table, filter) {
20
20
  return null;
21
21
  }
22
22
  }
23
- exports.handleSelect = handleSelect;
@@ -1,3 +1,3 @@
1
- import { DataTypes } from 'brackets-manager/dist/types';
1
+ import { DataTypes, Id } from 'brackets-model';
2
2
  import { PrismaClient } from '@prisma/client';
3
- export declare function handleGroupUpdate(prisma: PrismaClient, filter: Partial<DataTypes['group']> | number, value: Partial<DataTypes['group']> | DataTypes['group']): Promise<boolean>;
3
+ export declare function handleGroupUpdate(prisma: PrismaClient, filter: Partial<DataTypes['group']> | Id, value: Partial<DataTypes['group']> | DataTypes['group']): Promise<boolean>;
@@ -1,36 +1,42 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.handleGroupUpdate = void 0;
3
+ exports.handleGroupUpdate = handleGroupUpdate;
4
+ const prisma_id_1 = require("../../prisma-id");
4
5
  async function handleGroupUpdate(prisma, filter, value) {
5
- if (typeof filter === 'number') {
6
+ if ((0, prisma_id_1.isModelId)(filter)) {
6
7
  // Update by Id
7
- return prisma.group
8
- .update({
8
+ try {
9
+ await prisma.group.update({
10
+ where: {
11
+ id: (0, prisma_id_1.toPrismaId)(filter),
12
+ },
13
+ data: {
14
+ number: value.number,
15
+ stageId: (0, prisma_id_1.toPrismaId)(value.stage_id),
16
+ },
17
+ });
18
+ return true;
19
+ }
20
+ catch {
21
+ return false;
22
+ }
23
+ }
24
+ // Update by filter
25
+ try {
26
+ await prisma.group.updateMany({
9
27
  where: {
10
- id: filter,
28
+ id: (0, prisma_id_1.toPrismaId)(filter.id),
29
+ number: filter.number,
30
+ stageId: (0, prisma_id_1.toPrismaId)(filter.stage_id),
11
31
  },
12
32
  data: {
13
33
  number: value.number,
14
- stageId: value.stage_id,
34
+ stageId: (0, prisma_id_1.toPrismaId)(value.stage_id),
15
35
  },
16
- })
17
- .then(() => true)
18
- .catch(() => false);
36
+ });
37
+ return true;
38
+ }
39
+ catch {
40
+ return false;
19
41
  }
20
- // Update by filter
21
- return prisma.group
22
- .updateMany({
23
- where: {
24
- id: filter.id,
25
- number: filter.number,
26
- stageId: filter.stage_id,
27
- },
28
- data: {
29
- number: value.number,
30
- stageId: value.stage_id,
31
- },
32
- })
33
- .then(() => true)
34
- .catch(() => false);
35
42
  }
36
- exports.handleGroupUpdate = handleGroupUpdate;
@@ -1,3 +1,4 @@
1
1
  import { PrismaClient } from '@prisma/client';
2
+ import { Id } from 'brackets-model';
2
3
  import type { MatchGameWithExtra } from '../../types';
3
- export declare function handleMatchGameUpdate(prisma: PrismaClient, filter: Partial<MatchGameWithExtra> | number, value: Partial<MatchGameWithExtra> | MatchGameWithExtra): Promise<boolean>;
4
+ export declare function handleMatchGameUpdate(prisma: PrismaClient, filter: Partial<MatchGameWithExtra> | Id, value: Partial<MatchGameWithExtra> | MatchGameWithExtra): Promise<boolean>;
@@ -1,12 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.handleMatchGameUpdate = void 0;
3
+ exports.handleMatchGameUpdate = handleMatchGameUpdate;
4
4
  const transformers_1 = require("../../transformers");
5
+ const prisma_id_1 = require("../../prisma-id");
5
6
  function getParticipantResultUpsertData(value) {
6
7
  return {
7
8
  upsert: {
8
9
  update: {
9
- participantId: value.id,
10
+ participantId: (0, prisma_id_1.toPrismaId)(value.id),
10
11
  forfeit: value.forfeit,
11
12
  position: value.position,
12
13
  score: value.score,
@@ -15,7 +16,7 @@ function getParticipantResultUpsertData(value) {
15
16
  : undefined,
16
17
  },
17
18
  create: {
18
- participantId: value.id,
19
+ participantId: (0, prisma_id_1.toPrismaId)(value.id),
19
20
  forfeit: value.forfeit,
20
21
  position: value.position,
21
22
  score: value.score,
@@ -30,8 +31,8 @@ function getUpdateData(value, previousExtra) {
30
31
  const extrasInput = value;
31
32
  const extra = (0, transformers_1.matchGameExtraFromInput)(extrasInput, previousExtra);
32
33
  return {
33
- stageId: value.stage_id,
34
- matchId: value.parent_id,
34
+ stageId: (0, prisma_id_1.toPrismaId)(value.stage_id),
35
+ matchId: (0, prisma_id_1.toPrismaId)(value.parent_id),
35
36
  number: value.number,
36
37
  status: value.status
37
38
  ? transformers_1.MatchStatusTransformer.to(value.status)
@@ -49,20 +50,20 @@ async function updateById(prisma, id, value, previousExtra) {
49
50
  let extraSource = previousExtra ?? null;
50
51
  if (previousExtra === undefined) {
51
52
  const existing = await prisma.matchGame.findUnique({
52
- where: { id },
53
+ where: { id: (0, prisma_id_1.toPrismaId)(id) },
53
54
  select: { extra: true },
54
55
  });
55
56
  extraSource = existing?.extra ?? null;
56
57
  }
57
58
  return prisma.matchGame.update({
58
59
  where: {
59
- id,
60
+ id: (0, prisma_id_1.toPrismaId)(id),
60
61
  },
61
62
  data: getUpdateData(value, extraSource),
62
63
  });
63
64
  }
64
65
  async function handleMatchGameUpdate(prisma, filter, value) {
65
- if (typeof filter === 'number') {
66
+ if ((0, prisma_id_1.isModelId)(filter)) {
66
67
  // Update by Id
67
68
  try {
68
69
  await updateById(prisma, filter, value);
@@ -75,10 +76,10 @@ async function handleMatchGameUpdate(prisma, filter, value) {
75
76
  try {
76
77
  const games = await prisma.matchGame.findMany({
77
78
  where: {
78
- id: filter.id,
79
+ id: (0, prisma_id_1.toPrismaId)(filter.id),
79
80
  number: filter.number,
80
- stageId: filter.stage_id,
81
- matchId: filter.parent_id,
81
+ stageId: (0, prisma_id_1.toPrismaId)(filter.stage_id),
82
+ matchId: (0, prisma_id_1.toPrismaId)(filter.parent_id),
82
83
  status: filter.status
83
84
  ? transformers_1.MatchStatusTransformer.to(filter.status)
84
85
  : undefined,
@@ -91,4 +92,3 @@ async function handleMatchGameUpdate(prisma, filter, value) {
91
92
  return false;
92
93
  }
93
94
  }
94
- exports.handleMatchGameUpdate = handleMatchGameUpdate;
@@ -1,3 +1,4 @@
1
1
  import { PrismaClient } from '@prisma/client';
2
+ import { Id } from 'brackets-model';
2
3
  import type { MatchWithExtra } from '../../types';
3
- export declare function handleMatchUpdate(prisma: PrismaClient, filter: Partial<MatchWithExtra> | number, value: Partial<MatchWithExtra> | MatchWithExtra): Promise<boolean>;
4
+ export declare function handleMatchUpdate(prisma: PrismaClient, filter: Partial<MatchWithExtra> | Id, value: Partial<MatchWithExtra> | MatchWithExtra): Promise<boolean>;
@@ -1,12 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.handleMatchUpdate = void 0;
3
+ exports.handleMatchUpdate = handleMatchUpdate;
4
4
  const transformers_1 = require("../../transformers");
5
+ const prisma_id_1 = require("../../prisma-id");
5
6
  function getParticipantResultUpsertData(value) {
6
7
  return {
7
8
  upsert: {
8
9
  update: {
9
- participantId: value.id,
10
+ participantId: (0, prisma_id_1.toPrismaId)(value.id),
10
11
  forfeit: value.forfeit,
11
12
  position: value.position,
12
13
  score: value.score,
@@ -15,7 +16,7 @@ function getParticipantResultUpsertData(value) {
15
16
  : undefined,
16
17
  },
17
18
  create: {
18
- participantId: value.id,
19
+ participantId: (0, prisma_id_1.toPrismaId)(value.id),
19
20
  forfeit: value.forfeit,
20
21
  position: value.position,
21
22
  score: value.score,
@@ -30,9 +31,9 @@ function getUpdateData(value, previousExtra) {
30
31
  const extrasInput = value;
31
32
  const extra = (0, transformers_1.matchExtraFromInput)(extrasInput, previousExtra);
32
33
  return {
33
- stageId: value.stage_id,
34
- groupId: value.group_id,
35
- roundId: value.round_id,
34
+ stageId: (0, prisma_id_1.toPrismaId)(value.stage_id),
35
+ groupId: (0, prisma_id_1.toPrismaId)(value.group_id),
36
+ roundId: (0, prisma_id_1.toPrismaId)(value.round_id),
36
37
  childCount: value.child_count,
37
38
  number: value.number,
38
39
  status: value.status
@@ -51,20 +52,20 @@ async function updateById(prisma, id, value, previousExtra) {
51
52
  let extraSource = previousExtra ?? null;
52
53
  if (previousExtra === undefined) {
53
54
  const existing = await prisma.match.findUnique({
54
- where: { id },
55
+ where: { id: (0, prisma_id_1.toPrismaId)(id) },
55
56
  select: { extra: true },
56
57
  });
57
58
  extraSource = existing?.extra ?? null;
58
59
  }
59
60
  return prisma.match.update({
60
61
  where: {
61
- id,
62
+ id: (0, prisma_id_1.toPrismaId)(id),
62
63
  },
63
64
  data: getUpdateData(value, extraSource),
64
65
  });
65
66
  }
66
67
  async function handleMatchUpdate(prisma, filter, value) {
67
- if (typeof filter === 'number') {
68
+ if ((0, prisma_id_1.isModelId)(filter)) {
68
69
  // Update by Id
69
70
  try {
70
71
  await updateById(prisma, filter, value);
@@ -77,11 +78,11 @@ async function handleMatchUpdate(prisma, filter, value) {
77
78
  try {
78
79
  const matches = await prisma.match.findMany({
79
80
  where: {
80
- id: filter.id,
81
+ id: (0, prisma_id_1.toPrismaId)(filter.id),
81
82
  number: filter.number,
82
- stageId: filter.stage_id,
83
- groupId: filter.group_id,
84
- roundId: filter.round_id,
83
+ stageId: (0, prisma_id_1.toPrismaId)(filter.stage_id),
84
+ groupId: (0, prisma_id_1.toPrismaId)(filter.group_id),
85
+ roundId: (0, prisma_id_1.toPrismaId)(filter.round_id),
85
86
  status: filter.status
86
87
  ? transformers_1.MatchStatusTransformer.to(filter.status)
87
88
  : undefined,
@@ -94,4 +95,3 @@ async function handleMatchUpdate(prisma, filter, value) {
94
95
  return false;
95
96
  }
96
97
  }
97
- exports.handleMatchUpdate = handleMatchUpdate;
@@ -1,3 +1,3 @@
1
- import { DataTypes } from 'brackets-manager/dist/types';
1
+ import { DataTypes, Id } from 'brackets-model';
2
2
  import { PrismaClient } from '@prisma/client';
3
- export declare function handleParticipantUpdate(prisma: PrismaClient, filter: Partial<DataTypes['participant']> | number, value: Partial<DataTypes['participant']> | DataTypes['participant']): Promise<boolean>;
3
+ export declare function handleParticipantUpdate(prisma: PrismaClient, filter: Partial<DataTypes['participant']> | Id, value: Partial<DataTypes['participant']> | DataTypes['participant']): Promise<boolean>;
@@ -1,39 +1,45 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.handleParticipantUpdate = void 0;
3
+ exports.handleParticipantUpdate = handleParticipantUpdate;
4
4
  const transformers_1 = require("../../transformers");
5
+ const prisma_id_1 = require("../../prisma-id");
5
6
  async function handleParticipantUpdate(prisma, filter, value) {
6
- if (typeof filter === 'number') {
7
+ if ((0, prisma_id_1.isModelId)(filter)) {
7
8
  // Update by Id
8
- return prisma.participant
9
- .update({
9
+ try {
10
+ await prisma.participant.update({
11
+ where: {
12
+ id: (0, prisma_id_1.toPrismaId)(filter),
13
+ },
14
+ data: {
15
+ name: value.name,
16
+ tournamentId: (0, prisma_id_1.toPrismaId)(value.tournament_id),
17
+ extra: (0, transformers_1.participantExtraFromInput)(value) ?? undefined,
18
+ },
19
+ });
20
+ return true;
21
+ }
22
+ catch {
23
+ return false;
24
+ }
25
+ }
26
+ // Update by filter
27
+ try {
28
+ await prisma.participant.updateMany({
10
29
  where: {
11
- id: filter,
30
+ id: (0, prisma_id_1.toPrismaId)(filter.id),
31
+ name: filter.name,
32
+ tournamentId: (0, prisma_id_1.toPrismaId)(filter.tournament_id),
12
33
  },
13
34
  data: {
14
35
  name: value.name,
15
- tournamentId: value.tournament_id,
36
+ tournamentId: (0, prisma_id_1.toPrismaId)(value.tournament_id),
16
37
  extra: (0, transformers_1.participantExtraFromInput)(value) ?? undefined,
17
38
  },
18
- })
19
- .then(() => true)
20
- .catch(() => false);
39
+ });
40
+ return true;
41
+ }
42
+ catch {
43
+ return false;
21
44
  }
22
- // Update by filter
23
- return prisma.participant
24
- .updateMany({
25
- where: {
26
- id: filter.id,
27
- name: filter.name,
28
- tournamentId: filter.tournament_id,
29
- },
30
- data: {
31
- name: value.name,
32
- tournamentId: value.tournament_id,
33
- extra: (0, transformers_1.participantExtraFromInput)(value) ?? undefined,
34
- },
35
- })
36
- .then(() => true)
37
- .catch(() => false);
38
45
  }
39
- exports.handleParticipantUpdate = handleParticipantUpdate;
@@ -1,3 +1,3 @@
1
- import { DataTypes } from 'brackets-manager/dist/types';
1
+ import { DataTypes, Id } from 'brackets-model';
2
2
  import { PrismaClient } from '@prisma/client';
3
- export declare function handleRoundUpdate(prisma: PrismaClient, filter: Partial<DataTypes['round']> | number, value: Partial<DataTypes['round']> | DataTypes['round']): Promise<boolean>;
3
+ export declare function handleRoundUpdate(prisma: PrismaClient, filter: Partial<DataTypes['round']> | Id, value: Partial<DataTypes['round']> | DataTypes['round']): Promise<boolean>;
@@ -1,39 +1,45 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.handleRoundUpdate = void 0;
3
+ exports.handleRoundUpdate = handleRoundUpdate;
4
+ const prisma_id_1 = require("../../prisma-id");
4
5
  async function handleRoundUpdate(prisma, filter, value) {
5
- if (typeof filter === 'number') {
6
+ if ((0, prisma_id_1.isModelId)(filter)) {
6
7
  // Update by Id
7
- return prisma.round
8
- .update({
8
+ try {
9
+ await prisma.round.update({
10
+ where: {
11
+ id: (0, prisma_id_1.toPrismaId)(filter),
12
+ },
13
+ data: {
14
+ number: value.number,
15
+ stageId: (0, prisma_id_1.toPrismaId)(value.stage_id),
16
+ groupId: (0, prisma_id_1.toPrismaId)(value.group_id),
17
+ },
18
+ });
19
+ return true;
20
+ }
21
+ catch {
22
+ return false;
23
+ }
24
+ }
25
+ // Update by filter
26
+ try {
27
+ await prisma.round.updateMany({
9
28
  where: {
10
- id: filter,
29
+ id: (0, prisma_id_1.toPrismaId)(filter.id),
30
+ number: filter.number,
31
+ stageId: (0, prisma_id_1.toPrismaId)(filter.stage_id),
32
+ groupId: (0, prisma_id_1.toPrismaId)(filter.group_id),
11
33
  },
12
34
  data: {
13
35
  number: value.number,
14
- stageId: value.stage_id,
15
- groupId: value.group_id,
36
+ stageId: (0, prisma_id_1.toPrismaId)(value.stage_id),
37
+ groupId: (0, prisma_id_1.toPrismaId)(value.group_id),
16
38
  },
17
- })
18
- .then(() => true)
19
- .catch(() => false);
39
+ });
40
+ return true;
41
+ }
42
+ catch {
43
+ return false;
20
44
  }
21
- // Update by filter
22
- return prisma.round
23
- .updateMany({
24
- where: {
25
- id: filter.id,
26
- number: filter.number,
27
- stageId: filter.stage_id,
28
- groupId: filter.group_id,
29
- },
30
- data: {
31
- number: value.number,
32
- stageId: value.stage_id,
33
- groupId: value.group_id,
34
- },
35
- })
36
- .then(() => true)
37
- .catch(() => false);
38
45
  }
39
- exports.handleRoundUpdate = handleRoundUpdate;
@@ -1,3 +1,3 @@
1
- import { DataTypes } from 'brackets-manager/dist/types';
1
+ import { DataTypes, Id } from 'brackets-model';
2
2
  import { PrismaClient } from '@prisma/client';
3
- export declare function handleStageUpdate(prisma: PrismaClient, filter: Partial<DataTypes['stage']> | number, value: Partial<DataTypes['stage']> | DataTypes['stage']): Promise<boolean>;
3
+ export declare function handleStageUpdate(prisma: PrismaClient, filter: Partial<DataTypes['stage']> | Id, value: Partial<DataTypes['stage']> | DataTypes['stage']): Promise<boolean>;