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.
- package/README.md +15 -24
- package/dist/prisma-id.d.ts +10 -0
- package/dist/prisma-id.js +32 -0
- package/dist/storage-handlers/delete-handlers/group.d.ts +1 -1
- package/dist/storage-handlers/delete-handlers/group.js +24 -15
- package/dist/storage-handlers/delete-handlers/match-game.d.ts +1 -1
- package/dist/storage-handlers/delete-handlers/match-game.js +25 -16
- package/dist/storage-handlers/delete-handlers/match.d.ts +1 -1
- package/dist/storage-handlers/delete-handlers/match.js +26 -17
- package/dist/storage-handlers/delete-handlers/participant.d.ts +1 -1
- package/dist/storage-handlers/delete-handlers/participant.js +24 -15
- package/dist/storage-handlers/delete-handlers/round.d.ts +1 -1
- package/dist/storage-handlers/delete-handlers/round.js +25 -16
- package/dist/storage-handlers/delete-handlers/stage.d.ts +1 -1
- package/dist/storage-handlers/delete-handlers/stage.js +32 -29
- package/dist/storage-handlers/delete.d.ts +1 -1
- package/dist/storage-handlers/delete.js +1 -2
- package/dist/storage-handlers/insert-handlers/group.d.ts +2 -2
- package/dist/storage-handlers/insert-handlers/group.js +16 -16
- package/dist/storage-handlers/insert-handlers/match-game.d.ts +2 -2
- package/dist/storage-handlers/insert-handlers/match-game.js +19 -18
- package/dist/storage-handlers/insert-handlers/match.d.ts +2 -2
- package/dist/storage-handlers/insert-handlers/match.js +19 -18
- package/dist/storage-handlers/insert-handlers/participant.d.ts +2 -2
- package/dist/storage-handlers/insert-handlers/participant.js +20 -20
- package/dist/storage-handlers/insert-handlers/round.d.ts +2 -2
- package/dist/storage-handlers/insert-handlers/round.js +16 -16
- package/dist/storage-handlers/insert-handlers/stage.d.ts +2 -2
- package/dist/storage-handlers/insert-handlers/stage.js +26 -26
- package/dist/storage-handlers/insert.d.ts +1 -1
- package/dist/storage-handlers/insert.js +1 -2
- package/dist/storage-handlers/select-handlers/group.d.ts +2 -2
- package/dist/storage-handlers/select-handlers/group.js +34 -28
- package/dist/storage-handlers/select-handlers/match-game.d.ts +2 -1
- package/dist/storage-handlers/select-handlers/match-game.js +49 -42
- package/dist/storage-handlers/select-handlers/match.d.ts +2 -1
- package/dist/storage-handlers/select-handlers/match.js +59 -52
- package/dist/storage-handlers/select-handlers/participant.d.ts +2 -2
- package/dist/storage-handlers/select-handlers/participant.js +31 -24
- package/dist/storage-handlers/select-handlers/round.d.ts +2 -2
- package/dist/storage-handlers/select-handlers/round.js +35 -28
- package/dist/storage-handlers/select-handlers/stage.d.ts +2 -2
- package/dist/storage-handlers/select-handlers/stage.js +54 -47
- package/dist/storage-handlers/select.d.ts +2 -2
- package/dist/storage-handlers/select.js +1 -2
- package/dist/storage-handlers/update-handlers/group.d.ts +2 -2
- package/dist/storage-handlers/update-handlers/group.js +31 -25
- package/dist/storage-handlers/update-handlers/match-game.d.ts +2 -1
- package/dist/storage-handlers/update-handlers/match-game.js +12 -12
- package/dist/storage-handlers/update-handlers/match.d.ts +2 -1
- package/dist/storage-handlers/update-handlers/match.js +14 -14
- package/dist/storage-handlers/update-handlers/participant.d.ts +2 -2
- package/dist/storage-handlers/update-handlers/participant.js +32 -26
- package/dist/storage-handlers/update-handlers/round.d.ts +2 -2
- package/dist/storage-handlers/update-handlers/round.js +34 -28
- package/dist/storage-handlers/update-handlers/stage.d.ts +2 -2
- package/dist/storage-handlers/update-handlers/stage.js +46 -43
- package/dist/storage-handlers/update.d.ts +2 -2
- package/dist/storage-handlers/update.js +1 -2
- package/dist/storage.d.ts +3 -4
- package/dist/transformers/enum/grand-final-type.js +17 -7
- package/dist/transformers/enum/match-result.js +17 -7
- package/dist/transformers/enum/match-status.d.ts +1 -1
- package/dist/transformers/enum/match-status.js +21 -7
- package/dist/transformers/enum/round-robin-mode.js +17 -7
- package/dist/transformers/enum/seed-ordering.js +17 -7
- package/dist/transformers/enum/stage-type.js +17 -7
- package/dist/transformers/model/group.d.ts +1 -1
- package/dist/transformers/model/group.js +2 -1
- package/dist/transformers/model/match-game.d.ts +3 -3
- package/dist/transformers/model/match-game.js +5 -4
- package/dist/transformers/model/match.d.ts +3 -3
- package/dist/transformers/model/match.js +6 -5
- package/dist/transformers/model/participant-result.d.ts +1 -1
- package/dist/transformers/model/participant.d.ts +3 -3
- package/dist/transformers/model/participant.js +4 -3
- package/dist/transformers/model/round.d.ts +1 -1
- package/dist/transformers/model/round.js +3 -2
- package/dist/transformers/model/stage-settings.d.ts +2 -2
- package/dist/transformers/model/stage.d.ts +2 -2
- package/dist/transformers/model/stage.js +2 -1
- package/dist/types.d.ts +1 -1
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -1,33 +1,23 @@
|
|
|
1
1
|
# brackets-prisma-db
|
|
2
2
|
|
|
3
3
|
This implementation of the [`CrudInterface`](https://drarig29.github.io/brackets-docs/reference/manager/interfaces/CrudInterface.html)
|
|
4
|
-
uses [
|
|
5
|
-
|
|
6
|
-
> **Warning**
|
|
7
|
-
> This implementation has not been full tested yet. Use with caution.
|
|
8
|
-
|
|
9
|
-
## Limitations
|
|
10
|
-
|
|
11
|
-
Currently there are some features of the [manager](https://github.com/Drarig29/brackets-manager.js) that can't be used.
|
|
12
|
-
|
|
13
|
-
| **Feature** | **Status** |
|
|
14
|
-
| ------------------- | ----------- |
|
|
15
|
-
| Custom Participants | Implemented |
|
|
16
|
-
| Custom Matches | Implemented |
|
|
4
|
+
uses [Prisma](https://www.prisma.io/) to store the data in a SQL database.
|
|
17
5
|
|
|
18
6
|
## Usage
|
|
19
7
|
|
|
20
|
-
To use this implementation make sure you have [
|
|
21
|
-
A Guide on how to include prisma in your project can be found on the official documentation page.
|
|
8
|
+
To use this implementation, make sure you have [Prisma](https://www.prisma.io/) included in your project. You may follow their [Getting Started](https://www.prisma.io/docs/getting-started) guide.
|
|
22
9
|
|
|
23
|
-
Once [
|
|
10
|
+
Once [Prisma](https://www.prisma.io/) is included in your project, copy the [`schema.prisma`](./prisma/schema.prisma) into your project.
|
|
24
11
|
If you have an existing `schema.prisma` in your project copy and paste the schema definitions into your existing one.
|
|
25
12
|
|
|
26
|
-
>
|
|
13
|
+
> [!WARNING]
|
|
27
14
|
> Do not rename any of the models or enums provided! This **will** break the implementation.
|
|
28
15
|
|
|
29
|
-
Next generate the
|
|
30
|
-
|
|
16
|
+
Next, generate the Prisma client using `npx prisma generate`.
|
|
17
|
+
|
|
18
|
+
And lastly, push the definition to your database using `npx prisma db push`.
|
|
19
|
+
|
|
20
|
+
### Minimal example
|
|
31
21
|
|
|
32
22
|
```typescript
|
|
33
23
|
import { SqlDatabase } from 'brackets-prisma-db';
|
|
@@ -41,7 +31,7 @@ const storage = new SqlDatabase(prisma);
|
|
|
41
31
|
const manager = new BracketsManager(storage);
|
|
42
32
|
```
|
|
43
33
|
|
|
44
|
-
Example with custom matches and participants
|
|
34
|
+
### Example with custom matches and participants
|
|
45
35
|
|
|
46
36
|
```typescript
|
|
47
37
|
import { SqlDatabase } from 'brackets-prisma-db'
|
|
@@ -50,6 +40,8 @@ import { BracketsManager } from 'brackets-manager'
|
|
|
50
40
|
import type { Match } from 'brackets-model'
|
|
51
41
|
|
|
52
42
|
type MatchWithWeather = Match & {
|
|
43
|
+
// The schema defines a JSON column named `extra` in the `Match` and `MatchGame` tables.
|
|
44
|
+
// Anything you put in the `extra` object will be stored in that column.
|
|
53
45
|
extra: {
|
|
54
46
|
weather: 'sunny' | 'rainy' | 'cloudy' | 'snowy'
|
|
55
47
|
}
|
|
@@ -63,6 +55,7 @@ const stage = await manager.create.stage({
|
|
|
63
55
|
name: 'Example',
|
|
64
56
|
type: 'single_elimination',
|
|
65
57
|
seeding: [
|
|
58
|
+
// Only `name` is mandatory. All other properties are stored in the `Participant` table rows.
|
|
66
59
|
{ name: 'Team 1', color: 'red' },
|
|
67
60
|
{ name: 'Team 2', color: 'blue' },
|
|
68
61
|
{ name: 'Team 3', color: 'green' },
|
|
@@ -74,12 +67,10 @@ const currentMatches = await manager.get.currentMatches(stage.id)
|
|
|
74
67
|
|
|
75
68
|
await manager.update.match<MatchWithWeather>({
|
|
76
69
|
id: currentMatches[0].id,
|
|
77
|
-
opponent1: { result: 'win' },
|
|
70
|
+
opponent1: { score: 6, result: 'win' },
|
|
71
|
+
opponent2: { score: 3, result: 'loss' },
|
|
78
72
|
extra: {
|
|
79
73
|
weather: 'sunny',
|
|
80
74
|
},
|
|
81
75
|
})
|
|
82
|
-
|
|
83
|
-
const database = await manager.get.tournamentData(1)
|
|
84
|
-
console.log(database)
|
|
85
76
|
```
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Id } from 'brackets-model';
|
|
2
|
+
export declare class InvalidPrismaIdError extends Error {
|
|
3
|
+
constructor(id: Id);
|
|
4
|
+
}
|
|
5
|
+
export declare function isModelId(value: unknown): value is Id;
|
|
6
|
+
export declare function toPrismaId(id: Id): number;
|
|
7
|
+
export declare function toPrismaId(id: null): null;
|
|
8
|
+
export declare function toPrismaId(id: undefined): undefined;
|
|
9
|
+
export declare function toPrismaId(id: Id | null): number | null;
|
|
10
|
+
export declare function toPrismaId(id: Id | undefined): number | undefined;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InvalidPrismaIdError = void 0;
|
|
4
|
+
exports.isModelId = isModelId;
|
|
5
|
+
exports.toPrismaId = toPrismaId;
|
|
6
|
+
class InvalidPrismaIdError extends Error {
|
|
7
|
+
constructor(id) {
|
|
8
|
+
super(`Invalid Prisma integer id: ${JSON.stringify(id)}`);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.InvalidPrismaIdError = InvalidPrismaIdError;
|
|
12
|
+
function isModelId(value) {
|
|
13
|
+
return typeof value === 'number' || typeof value === 'string';
|
|
14
|
+
}
|
|
15
|
+
function toPrismaId(id) {
|
|
16
|
+
if (id === null || id === undefined) {
|
|
17
|
+
return id;
|
|
18
|
+
}
|
|
19
|
+
if (typeof id === 'number') {
|
|
20
|
+
if (Number.isSafeInteger(id)) {
|
|
21
|
+
return id;
|
|
22
|
+
}
|
|
23
|
+
throw new InvalidPrismaIdError(id);
|
|
24
|
+
}
|
|
25
|
+
if (/^-?\d+$/.test(id)) {
|
|
26
|
+
const numericId = Number(id);
|
|
27
|
+
if (Number.isSafeInteger(numericId)) {
|
|
28
|
+
return numericId;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
throw new InvalidPrismaIdError(id);
|
|
32
|
+
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { DataTypes } from 'brackets-
|
|
1
|
+
import { DataTypes } from 'brackets-model';
|
|
2
2
|
import { PrismaClient } from '@prisma/client';
|
|
3
3
|
export declare function handleGroupDelete(prisma: PrismaClient, filter?: Partial<DataTypes['group']>): Promise<boolean>;
|
|
@@ -1,23 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.handleGroupDelete =
|
|
3
|
+
exports.handleGroupDelete = handleGroupDelete;
|
|
4
|
+
const prisma_id_1 = require("../../prisma-id");
|
|
4
5
|
async function handleGroupDelete(prisma, filter) {
|
|
5
6
|
// No filter so delete everything
|
|
6
7
|
if (!filter) {
|
|
7
|
-
|
|
8
|
-
.deleteMany({})
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
try {
|
|
9
|
+
await prisma.group.deleteMany({});
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
11
15
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
stageId: filter.stage_id,
|
|
16
|
+
try {
|
|
17
|
+
const where = {
|
|
18
|
+
id: (0, prisma_id_1.toPrismaId)(filter.id),
|
|
19
|
+
stageId: (0, prisma_id_1.toPrismaId)(filter.stage_id),
|
|
17
20
|
number: filter.number,
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
};
|
|
22
|
+
await prisma.group.deleteMany({ where });
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
// An unsupported storage ID should behave like a filter that matched no rows.
|
|
27
|
+
if (error instanceof prisma_id_1.InvalidPrismaIdError) {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
22
32
|
}
|
|
23
|
-
exports.handleGroupDelete = handleGroupDelete;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { DataTypes } from 'brackets-
|
|
1
|
+
import { DataTypes } from 'brackets-model';
|
|
2
2
|
import { PrismaClient } from '@prisma/client';
|
|
3
3
|
export declare function handleMatchGameDelete(prisma: PrismaClient, filter?: Partial<DataTypes['match_game']>): Promise<boolean>;
|
|
@@ -1,28 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.handleMatchGameDelete =
|
|
3
|
+
exports.handleMatchGameDelete = handleMatchGameDelete;
|
|
4
4
|
const transformers_1 = require("../../transformers");
|
|
5
|
+
const prisma_id_1 = require("../../prisma-id");
|
|
5
6
|
async function handleMatchGameDelete(prisma, filter) {
|
|
6
7
|
// No filter so delete everything
|
|
7
8
|
if (!filter) {
|
|
8
|
-
|
|
9
|
-
.deleteMany({})
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
try {
|
|
10
|
+
await prisma.matchGame.deleteMany({});
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
12
16
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
matchId: filter.parent_id,
|
|
17
|
+
try {
|
|
18
|
+
const where = {
|
|
19
|
+
id: (0, prisma_id_1.toPrismaId)(filter.id),
|
|
20
|
+
stageId: (0, prisma_id_1.toPrismaId)(filter.stage_id),
|
|
21
|
+
matchId: (0, prisma_id_1.toPrismaId)(filter.parent_id),
|
|
19
22
|
number: filter.number,
|
|
20
23
|
status: filter.status
|
|
21
24
|
? transformers_1.MatchStatusTransformer.to(filter.status)
|
|
22
25
|
: undefined,
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
};
|
|
27
|
+
await prisma.matchGame.deleteMany({ where });
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
// An unsupported storage ID should behave like a filter that matched no rows.
|
|
32
|
+
if (error instanceof prisma_id_1.InvalidPrismaIdError) {
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
27
37
|
}
|
|
28
|
-
exports.handleMatchGameDelete = handleMatchGameDelete;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { DataTypes } from 'brackets-
|
|
1
|
+
import { DataTypes } from 'brackets-model';
|
|
2
2
|
import { PrismaClient } from '@prisma/client';
|
|
3
3
|
export declare function handleMatchDelete(prisma: PrismaClient, filter?: Partial<DataTypes['match']>): Promise<boolean>;
|
|
@@ -1,29 +1,38 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.handleMatchDelete =
|
|
3
|
+
exports.handleMatchDelete = handleMatchDelete;
|
|
4
4
|
const transformers_1 = require("../../transformers");
|
|
5
|
+
const prisma_id_1 = require("../../prisma-id");
|
|
5
6
|
async function handleMatchDelete(prisma, filter) {
|
|
6
7
|
// No filter so delete everything
|
|
7
8
|
if (!filter) {
|
|
8
|
-
|
|
9
|
-
.deleteMany({})
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
try {
|
|
10
|
+
await prisma.match.deleteMany({});
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
12
16
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
roundId: filter.round_id,
|
|
17
|
+
try {
|
|
18
|
+
const where = {
|
|
19
|
+
id: (0, prisma_id_1.toPrismaId)(filter.id),
|
|
20
|
+
stageId: (0, prisma_id_1.toPrismaId)(filter.stage_id),
|
|
21
|
+
groupId: (0, prisma_id_1.toPrismaId)(filter.group_id),
|
|
22
|
+
roundId: (0, prisma_id_1.toPrismaId)(filter.round_id),
|
|
20
23
|
number: filter.number,
|
|
21
24
|
status: filter.status
|
|
22
25
|
? transformers_1.MatchStatusTransformer.to(filter.status)
|
|
23
26
|
: undefined,
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
};
|
|
28
|
+
await prisma.match.deleteMany({ where });
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
// An unsupported storage ID should behave like a filter that matched no rows.
|
|
33
|
+
if (error instanceof prisma_id_1.InvalidPrismaIdError) {
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
28
38
|
}
|
|
29
|
-
exports.handleMatchDelete = handleMatchDelete;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { PrismaClient } from '@prisma/client';
|
|
2
|
-
import { DataTypes } from 'brackets-
|
|
2
|
+
import { DataTypes } from 'brackets-model';
|
|
3
3
|
export declare function handleParticipantDelete(prisma: PrismaClient, filter?: Partial<DataTypes['participant']>): Promise<boolean>;
|
|
@@ -1,23 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.handleParticipantDelete =
|
|
3
|
+
exports.handleParticipantDelete = handleParticipantDelete;
|
|
4
|
+
const prisma_id_1 = require("../../prisma-id");
|
|
4
5
|
async function handleParticipantDelete(prisma, filter) {
|
|
5
6
|
// No filter so delete everything
|
|
6
7
|
if (!filter) {
|
|
7
|
-
|
|
8
|
-
.deleteMany({})
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
try {
|
|
9
|
+
await prisma.participant.deleteMany({});
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
11
15
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
id: filter.id,
|
|
16
|
+
try {
|
|
17
|
+
const where = {
|
|
18
|
+
id: (0, prisma_id_1.toPrismaId)(filter.id),
|
|
16
19
|
name: filter.name,
|
|
17
|
-
tournamentId: filter.tournament_id,
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
tournamentId: (0, prisma_id_1.toPrismaId)(filter.tournament_id),
|
|
21
|
+
};
|
|
22
|
+
await prisma.participant.deleteMany({ where });
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
// An unsupported storage ID should behave like a filter that matched no rows.
|
|
27
|
+
if (error instanceof prisma_id_1.InvalidPrismaIdError) {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
22
32
|
}
|
|
23
|
-
exports.handleParticipantDelete = handleParticipantDelete;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { DataTypes } from 'brackets-
|
|
1
|
+
import { DataTypes } from 'brackets-model';
|
|
2
2
|
import { PrismaClient } from '@prisma/client';
|
|
3
3
|
export declare function handleRoundDelete(prisma: PrismaClient, filter?: Partial<DataTypes['round']>): Promise<boolean>;
|
|
@@ -1,24 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.handleRoundDelete =
|
|
3
|
+
exports.handleRoundDelete = handleRoundDelete;
|
|
4
|
+
const prisma_id_1 = require("../../prisma-id");
|
|
4
5
|
async function handleRoundDelete(prisma, filter) {
|
|
5
6
|
// No filter so delete everything
|
|
6
7
|
if (!filter) {
|
|
7
|
-
|
|
8
|
-
.deleteMany({})
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
try {
|
|
9
|
+
await prisma.round.deleteMany({});
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
11
15
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
groupId: filter.group_id,
|
|
16
|
+
try {
|
|
17
|
+
const where = {
|
|
18
|
+
id: (0, prisma_id_1.toPrismaId)(filter.id),
|
|
19
|
+
stageId: (0, prisma_id_1.toPrismaId)(filter.stage_id),
|
|
20
|
+
groupId: (0, prisma_id_1.toPrismaId)(filter.group_id),
|
|
18
21
|
number: filter.number,
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
};
|
|
23
|
+
await prisma.round.deleteMany({ where });
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
// An unsupported storage ID should behave like a filter that matched no rows.
|
|
28
|
+
if (error instanceof prisma_id_1.InvalidPrismaIdError) {
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
23
33
|
}
|
|
24
|
-
exports.handleRoundDelete = handleRoundDelete;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { DataTypes } from 'brackets-
|
|
1
|
+
import { DataTypes } from 'brackets-model';
|
|
2
2
|
import { PrismaClient } from '@prisma/client';
|
|
3
3
|
export declare function handleStageDelete(prisma: PrismaClient, filter?: Partial<DataTypes['stage']>): Promise<boolean>;
|
|
@@ -1,47 +1,50 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.handleStageDelete =
|
|
3
|
+
exports.handleStageDelete = handleStageDelete;
|
|
4
4
|
const transformers_1 = require("../../transformers");
|
|
5
|
+
const prisma_id_1 = require("../../prisma-id");
|
|
5
6
|
async function handleStageDelete(prisma, filter) {
|
|
6
|
-
|
|
7
|
-
.$transaction(async (tx) => {
|
|
8
|
-
// Build where clause if a filter is provided
|
|
7
|
+
try {
|
|
9
8
|
const where = filter
|
|
10
9
|
? {
|
|
11
|
-
id: filter.id,
|
|
10
|
+
id: (0, prisma_id_1.toPrismaId)(filter.id),
|
|
12
11
|
name: filter.name,
|
|
13
12
|
number: filter.number,
|
|
14
|
-
tournamentId: filter.tournament_id,
|
|
13
|
+
tournamentId: (0, prisma_id_1.toPrismaId)(filter.tournament_id),
|
|
15
14
|
type: filter.type
|
|
16
15
|
? transformers_1.StageTypeTransformer.to(filter.type)
|
|
17
16
|
: undefined,
|
|
18
17
|
}
|
|
19
18
|
: undefined;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
19
|
+
await prisma.$transaction(async (tx) => {
|
|
20
|
+
if (!where) {
|
|
21
|
+
// No filter: delete in the right order to satisfy FK constraints
|
|
22
|
+
await tx.stageSettings.deleteMany({});
|
|
23
|
+
await tx.stage.deleteMany({});
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
// Filtered delete: find matching stages
|
|
27
|
+
const stages = await tx.stage.findMany({
|
|
28
|
+
where,
|
|
29
|
+
select: { id: true },
|
|
30
|
+
});
|
|
31
|
+
if (stages.length === 0)
|
|
32
|
+
return true;
|
|
33
|
+
// Delete related StageSettings first to satisfy FK constraints
|
|
34
|
+
await tx.stageSettings.deleteMany({
|
|
35
|
+
where: { stageId: { in: stages.map((s) => s.id) } },
|
|
36
|
+
});
|
|
37
|
+
// Then delete the stages
|
|
38
|
+
await tx.stage.deleteMany({ where });
|
|
32
39
|
return true;
|
|
33
|
-
// Delete related StageSettings first to satisfy FK constraints
|
|
34
|
-
await tx.stageSettings.deleteMany({
|
|
35
|
-
where: { stageId: { in: stages.map((s) => s.id) } },
|
|
36
40
|
});
|
|
37
|
-
// Then delete the stages
|
|
38
|
-
await tx.stage.deleteMany({ where });
|
|
39
41
|
return true;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
// An unsupported storage ID should behave like a filter that matched no rows.
|
|
45
|
+
if (error instanceof prisma_id_1.InvalidPrismaIdError) {
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
44
48
|
return false;
|
|
45
|
-
}
|
|
49
|
+
}
|
|
46
50
|
}
|
|
47
|
-
exports.handleStageDelete = handleStageDelete;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { DataTypes } from 'brackets-
|
|
1
|
+
import { DataTypes } from 'brackets-model';
|
|
2
2
|
import { PrismaClient } from '@prisma/client';
|
|
3
3
|
export declare function handleDelete<T extends keyof DataTypes>(prisma: PrismaClient, table: T, filter?: Partial<DataTypes[T]>): Promise<boolean>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.handleDelete =
|
|
3
|
+
exports.handleDelete = handleDelete;
|
|
4
4
|
const delete_handlers_1 = require("./delete-handlers");
|
|
5
5
|
// Can't be named `delete` because its a reserved word...
|
|
6
6
|
async function handleDelete(prisma, table, filter) {
|
|
@@ -21,4 +21,3 @@ async function handleDelete(prisma, table, filter) {
|
|
|
21
21
|
return false;
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
-
exports.handleDelete = handleDelete;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { DataTypes, OmitId } from 'brackets-
|
|
1
|
+
import { DataTypes, OmitId } from 'brackets-model';
|
|
2
2
|
import { PrismaClient } from '@prisma/client';
|
|
3
|
-
export declare function handleGroupInsert(prisma: PrismaClient, values: OmitId<DataTypes['group']> | OmitId<DataTypes['group']>[]): Promise<number
|
|
3
|
+
export declare function handleGroupInsert(prisma: PrismaClient, values: OmitId<DataTypes['group']> | OmitId<DataTypes['group']>[]): Promise<number | boolean>;
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.handleGroupInsert =
|
|
3
|
+
exports.handleGroupInsert = handleGroupInsert;
|
|
4
4
|
const transformers_1 = require("../../transformers");
|
|
5
|
-
function handleGroupInsert(prisma, values) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
.createMany({
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
async function handleGroupInsert(prisma, values) {
|
|
6
|
+
try {
|
|
7
|
+
if (Array.isArray(values)) {
|
|
8
|
+
await prisma.group.createMany({
|
|
9
|
+
data: values.map(transformers_1.GroupTransformer.to),
|
|
10
|
+
});
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
const group = await prisma.group.create({
|
|
14
|
+
data: transformers_1.GroupTransformer.to(values),
|
|
15
|
+
});
|
|
16
|
+
return group.id;
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return Array.isArray(values) ? false : -1;
|
|
13
20
|
}
|
|
14
|
-
return prisma.group
|
|
15
|
-
.create({
|
|
16
|
-
data: transformers_1.GroupTransformer.to(values),
|
|
17
|
-
})
|
|
18
|
-
.then((v) => v.id)
|
|
19
|
-
.catch(() => -1);
|
|
20
21
|
}
|
|
21
|
-
exports.handleGroupInsert = handleGroupInsert;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { OmitId } from 'brackets-
|
|
1
|
+
import { OmitId } from 'brackets-model';
|
|
2
2
|
import { PrismaClient } from '@prisma/client';
|
|
3
3
|
import type { MatchGameWithExtra } from '../../types';
|
|
4
|
-
export declare function handleMatchGameInsert(prisma: PrismaClient, values: OmitId<MatchGameWithExtra> | OmitId<MatchGameWithExtra>[]): Promise<number
|
|
4
|
+
export declare function handleMatchGameInsert(prisma: PrismaClient, values: OmitId<MatchGameWithExtra> | OmitId<MatchGameWithExtra>[]): Promise<number | boolean>;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.handleMatchGameInsert =
|
|
3
|
+
exports.handleMatchGameInsert = handleMatchGameInsert;
|
|
4
4
|
const transformers_1 = require("../../transformers");
|
|
5
|
+
const prisma_id_1 = require("../../prisma-id");
|
|
5
6
|
function getCreationData(value) {
|
|
6
7
|
return {
|
|
7
8
|
...transformers_1.MatchGameTransformer.to(value),
|
|
@@ -9,7 +10,7 @@ function getCreationData(value) {
|
|
|
9
10
|
opponent1Result: value.opponent1
|
|
10
11
|
? {
|
|
11
12
|
create: {
|
|
12
|
-
participantId: value.opponent1.id,
|
|
13
|
+
participantId: (0, prisma_id_1.toPrismaId)(value.opponent1.id),
|
|
13
14
|
forfeit: value.opponent1.forfeit,
|
|
14
15
|
position: value.opponent1.position,
|
|
15
16
|
score: value.opponent1.score,
|
|
@@ -22,7 +23,7 @@ function getCreationData(value) {
|
|
|
22
23
|
opponent2Result: value.opponent2
|
|
23
24
|
? {
|
|
24
25
|
create: {
|
|
25
|
-
participantId: value.opponent2.id,
|
|
26
|
+
participantId: (0, prisma_id_1.toPrismaId)(value.opponent2.id),
|
|
26
27
|
forfeit: value.opponent2.forfeit,
|
|
27
28
|
position: value.opponent2.position,
|
|
28
29
|
score: value.opponent2.score,
|
|
@@ -34,20 +35,20 @@ function getCreationData(value) {
|
|
|
34
35
|
: undefined,
|
|
35
36
|
};
|
|
36
37
|
}
|
|
37
|
-
function handleMatchGameInsert(prisma, values) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
.createMany({
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
38
|
+
async function handleMatchGameInsert(prisma, values) {
|
|
39
|
+
try {
|
|
40
|
+
if (Array.isArray(values)) {
|
|
41
|
+
await prisma.matchGame.createMany({
|
|
42
|
+
data: values.map((v) => getCreationData(v)),
|
|
43
|
+
});
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
const matchGame = await prisma.matchGame.create({
|
|
47
|
+
data: getCreationData(values),
|
|
48
|
+
});
|
|
49
|
+
return matchGame.id;
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
return Array.isArray(values) ? false : -1;
|
|
45
53
|
}
|
|
46
|
-
return prisma.matchGame
|
|
47
|
-
.create({
|
|
48
|
-
data: getCreationData(values),
|
|
49
|
-
})
|
|
50
|
-
.then((v) => v.id)
|
|
51
|
-
.catch(() => -1);
|
|
52
54
|
}
|
|
53
|
-
exports.handleMatchGameInsert = handleMatchGameInsert;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { OmitId } from 'brackets-
|
|
1
|
+
import { OmitId } from 'brackets-model';
|
|
2
2
|
import { PrismaClient } from '@prisma/client';
|
|
3
3
|
import type { MatchWithExtra } from '../../types';
|
|
4
|
-
export declare function handleMatchInsert(prisma: PrismaClient, values: OmitId<MatchWithExtra> | OmitId<MatchWithExtra>[]): Promise<number
|
|
4
|
+
export declare function handleMatchInsert(prisma: PrismaClient, values: OmitId<MatchWithExtra> | OmitId<MatchWithExtra>[]): Promise<number | boolean>;
|