ballrush-core 0.2.0 → 0.2.2
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/domain/event-template.d.ts +1 -1
- package/dist/domain/event-template.js +2 -2
- package/dist/ports/event-templates.repository.d.ts +1 -1
- package/dist/ports/events.repository.d.ts +2 -2
- package/dist/ports/groups.repository.d.ts +2 -2
- package/dist/repositories/mongo/event-template.mapper.d.ts +2 -4
- package/dist/repositories/mongo/event-template.mapper.js +43 -29
- package/dist/repositories/mongo/event-template.repository.d.ts +2 -2
- package/dist/repositories/mongo/event-template.repository.js +8 -8
- package/dist/repositories/mongo/event.mapper.d.ts +2 -4
- package/dist/repositories/mongo/event.mapper.js +35 -37
- package/dist/repositories/mongo/event.repository.d.ts +3 -3
- package/dist/repositories/mongo/event.repository.js +13 -12
- package/dist/repositories/mongo/group.mapper.d.ts +2 -4
- package/dist/repositories/mongo/group.mapper.js +19 -21
- package/dist/repositories/mongo/group.repository.d.ts +3 -3
- package/dist/repositories/mongo/group.repository.js +9 -8
- package/dist/repositories/mongo/user.mapper.d.ts +1 -6
- package/package.json +1 -1
|
@@ -21,11 +21,11 @@ class EventTemplate {
|
|
|
21
21
|
this.createdAt = createdAt;
|
|
22
22
|
}
|
|
23
23
|
static create(p) {
|
|
24
|
-
if (!p.title
|
|
24
|
+
if (!p.title)
|
|
25
25
|
throw new Error("Title is required");
|
|
26
26
|
if (p.maxPlayers < 1)
|
|
27
27
|
throw new Error("maxPlayers must be >= 1");
|
|
28
|
-
return new EventTemplate(p.templateId, p.groupId, p.adminId, p.description
|
|
28
|
+
return new EventTemplate(p.templateId, p.groupId, p.adminId, p.description, p.title, p.preViewImg, [...p.options], p.autoPost ?? false, p.defaultTime, p.defaultDayOfWeek, p.defaultLocation, p.defaultDuration, [...(p.defaultParticipants ?? [])], p.maxPlayers, p.createdAt ?? new Date());
|
|
29
29
|
}
|
|
30
30
|
// ---- GETTERS
|
|
31
31
|
getTemplateId() { return this.templateId; }
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { EventTemplate } from "../domain/event-template";
|
|
2
2
|
import { ParticipantEvent } from "../types";
|
|
3
|
-
export interface
|
|
3
|
+
export interface EventTemplatesRepository {
|
|
4
4
|
getById(templateId: number): Promise<EventTemplate | null>;
|
|
5
5
|
getByGroupId(groupId: number): Promise<EventTemplate[]>;
|
|
6
6
|
getAll(): Promise<EventTemplate[]>;
|
|
@@ -16,11 +16,11 @@ export type EventWrite = {
|
|
|
16
16
|
reportMessageId?: number;
|
|
17
17
|
};
|
|
18
18
|
export interface EventsRepository {
|
|
19
|
-
create(eventData:
|
|
19
|
+
create(eventData: Event): Promise<Event>;
|
|
20
20
|
findById(eventId: number): Promise<Event | null>;
|
|
21
21
|
findByGroupAndStatuses(groupId: number, statuses: string[]): Promise<Event | null>;
|
|
22
22
|
findByTemplateAndGroup(templateId: number, groupId: number): Promise<Event | null>;
|
|
23
|
-
update(eventId: number, updates:
|
|
23
|
+
update(eventId: number, updates: Event): Promise<Event | null>;
|
|
24
24
|
findLastByGroup(groupId: number): Promise<Event | null>;
|
|
25
25
|
findAllByGroup(groupId: number): Promise<Event[]>;
|
|
26
26
|
countEvents(): Promise<number>;
|
|
@@ -15,9 +15,9 @@ export type GroupWrite = {
|
|
|
15
15
|
isMessageLast: boolean;
|
|
16
16
|
};
|
|
17
17
|
export interface GroupsRepository {
|
|
18
|
-
create(groupData:
|
|
18
|
+
create(groupData: Group): Promise<Group>;
|
|
19
19
|
findById(groupId: number): Promise<Group | null>;
|
|
20
|
-
update(groupId: number, updates:
|
|
20
|
+
update(groupId: number, updates: Group): Promise<Group | null>;
|
|
21
21
|
findAll(): Promise<Group[]>;
|
|
22
22
|
delete(groupId: number): Promise<void>;
|
|
23
23
|
}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { EventTemplate } from "../../domain/event-template";
|
|
2
2
|
import { EventTemplateDoc } from "../../mongo";
|
|
3
|
-
export declare
|
|
4
|
-
|
|
5
|
-
fromDoc(doc: EventTemplateDoc | (Omit<EventTemplateDoc, keyof any> & any)): EventTemplate;
|
|
6
|
-
};
|
|
3
|
+
export declare function toDomain(doc: EventTemplateDoc): EventTemplate;
|
|
4
|
+
export declare function toDoc(entity: EventTemplate): EventTemplateDoc;
|
|
@@ -1,36 +1,50 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.toDomain = toDomain;
|
|
4
|
+
exports.toDoc = toDoc;
|
|
4
5
|
const event_template_1 = require("../../domain/event-template");
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
defaultLocation: o.defaultLocation,
|
|
21
|
-
defaultDuration: o.defaultDuration,
|
|
22
|
-
defaultParticipants: o.defaultParticipants,
|
|
23
|
-
maxPlayers: o.maxPlayers,
|
|
24
|
-
createdAt: o.createdAt,
|
|
25
|
-
};
|
|
26
|
-
},
|
|
27
|
-
// Mongo doc/lean -> Domain
|
|
28
|
-
fromDoc(doc) {
|
|
29
|
-
return new event_template_1.EventTemplate(doc.templateId, doc.groupId, doc.adminId, doc.description, doc.title, doc.preViewImg, doc.options ?? [], doc.autoPost, doc.defaultTime, doc.defaultDayOfWeek, doc.defaultLocation, doc.defaultDuration, (doc.defaultParticipants ?? []).map((p) => ({
|
|
6
|
+
function toDomain(doc) {
|
|
7
|
+
return event_template_1.EventTemplate.create({
|
|
8
|
+
templateId: doc.templateId,
|
|
9
|
+
groupId: doc.groupId,
|
|
10
|
+
adminId: doc.adminId,
|
|
11
|
+
description: doc.description,
|
|
12
|
+
title: doc.title,
|
|
13
|
+
preViewImg: doc.preViewImg,
|
|
14
|
+
options: doc.options ?? [],
|
|
15
|
+
autoPost: doc.autoPost,
|
|
16
|
+
defaultTime: doc.defaultTime,
|
|
17
|
+
defaultDayOfWeek: doc.defaultDayOfWeek,
|
|
18
|
+
defaultLocation: doc.defaultLocation,
|
|
19
|
+
defaultDuration: doc.defaultDuration,
|
|
20
|
+
defaultParticipants: (doc.defaultParticipants ?? []).map((p) => ({
|
|
30
21
|
userId: p.userId,
|
|
31
22
|
voteOption: p.voteOption,
|
|
32
23
|
username: p.username,
|
|
33
24
|
votedAt: new Date(p.votedAt),
|
|
34
|
-
})),
|
|
35
|
-
|
|
36
|
-
|
|
25
|
+
})),
|
|
26
|
+
maxPlayers: doc.maxPlayers,
|
|
27
|
+
createdAt: new Date(doc.createdAt),
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
;
|
|
31
|
+
function toDoc(entity) {
|
|
32
|
+
return {
|
|
33
|
+
templateId: entity.getTemplateId(),
|
|
34
|
+
groupId: entity.getGroupId(),
|
|
35
|
+
adminId: entity.getAdminId(),
|
|
36
|
+
description: entity.getDescription(),
|
|
37
|
+
title: entity.getTitle(),
|
|
38
|
+
preViewImg: entity.getPreViewImg(),
|
|
39
|
+
options: entity.getOptions(),
|
|
40
|
+
autoPost: entity.getAutoPost(),
|
|
41
|
+
defaultTime: entity.getDefaultTime(),
|
|
42
|
+
defaultDayOfWeek: entity.getDefaultDayOfWeek(),
|
|
43
|
+
defaultLocation: entity.getDefaultLocation(),
|
|
44
|
+
defaultDuration: entity.getDefaultDuration(),
|
|
45
|
+
defaultParticipants: entity.getDefaultParticipants(),
|
|
46
|
+
maxPlayers: entity.getMaxPlayers(),
|
|
47
|
+
createdAt: entity.getCreatedAt(),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { Model } from "mongoose";
|
|
2
2
|
import type { EventTemplateDoc } from "../../mongo";
|
|
3
|
-
import type {
|
|
3
|
+
import type { EventTemplatesRepository } from "../../ports/event-templates.repository";
|
|
4
4
|
import type { ParticipantEvent } from "../../types";
|
|
5
5
|
import { EventTemplate } from "../../domain/event-template";
|
|
6
|
-
export declare class MongoEventTemplatesRepository implements
|
|
6
|
+
export declare class MongoEventTemplatesRepository implements EventTemplatesRepository {
|
|
7
7
|
private readonly Model;
|
|
8
8
|
constructor(Model: Model<EventTemplateDoc>);
|
|
9
9
|
getById(templateId: number): Promise<EventTemplate | null>;
|
|
@@ -8,32 +8,32 @@ class MongoEventTemplatesRepository {
|
|
|
8
8
|
}
|
|
9
9
|
async getById(templateId) {
|
|
10
10
|
const doc = await this.Model.findOne({ templateId }).lean();
|
|
11
|
-
return doc ? event_template_mapper_1.
|
|
11
|
+
return doc ? (0, event_template_mapper_1.toDomain)(doc) : null;
|
|
12
12
|
}
|
|
13
13
|
async getByGroupId(groupId) {
|
|
14
14
|
const docs = await this.Model.find({ groupId }).lean();
|
|
15
|
-
return docs.map(d => event_template_mapper_1.
|
|
15
|
+
return docs.map(d => (0, event_template_mapper_1.toDomain)(d));
|
|
16
16
|
}
|
|
17
17
|
async getAll() {
|
|
18
18
|
const docs = await this.Model.find().lean();
|
|
19
|
-
return docs.map(d => event_template_mapper_1.
|
|
19
|
+
return docs.map(d => (0, event_template_mapper_1.toDomain)(d));
|
|
20
20
|
}
|
|
21
21
|
async createFromDomain(entity) {
|
|
22
|
-
const write = event_template_mapper_1.
|
|
22
|
+
const write = (0, event_template_mapper_1.toDoc)(entity);
|
|
23
23
|
const saved = await new this.Model(write).save();
|
|
24
|
-
return event_template_mapper_1.
|
|
24
|
+
return (0, event_template_mapper_1.toDomain)(saved.toObject());
|
|
25
25
|
}
|
|
26
26
|
async updateFromDomain(entity) {
|
|
27
|
-
const write = event_template_mapper_1.
|
|
27
|
+
const write = (0, event_template_mapper_1.toDoc)(entity);
|
|
28
28
|
const updated = await this.Model.findOneAndUpdate({ templateId: entity.getTemplateId() }, write, { new: true }).lean();
|
|
29
|
-
return updated ? event_template_mapper_1.
|
|
29
|
+
return updated ? (0, event_template_mapper_1.toDomain)(updated) : null;
|
|
30
30
|
}
|
|
31
31
|
async deleteById(templateId) {
|
|
32
32
|
await this.Model.deleteOne({ templateId });
|
|
33
33
|
}
|
|
34
34
|
async setDefaultParticipants(templateId, participants) {
|
|
35
35
|
const doc = await this.Model.findOneAndUpdate({ templateId }, { $set: { defaultParticipants: participants } }, { new: true }).lean();
|
|
36
|
-
return doc ? event_template_mapper_1.
|
|
36
|
+
return doc ? (0, event_template_mapper_1.toDomain)(doc) : null;
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
exports.MongoEventTemplatesRepository = MongoEventTemplatesRepository;
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { EventDoc } from "../../mongo";
|
|
2
2
|
import { Event } from "../../domain/event";
|
|
3
3
|
import { EventWrite } from "../../ports/events.repository";
|
|
4
|
-
export declare
|
|
5
|
-
|
|
6
|
-
static toDoc(event: Event): Partial<EventWrite>;
|
|
7
|
-
}
|
|
4
|
+
export declare function toDomain(doc: EventDoc): Event;
|
|
5
|
+
export declare function toDoc(event: Event): EventWrite;
|
|
@@ -1,41 +1,39 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.toDomain = toDomain;
|
|
4
|
+
exports.toDoc = toDoc;
|
|
4
5
|
const event_1 = require("../../domain/event");
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
};
|
|
39
|
-
}
|
|
6
|
+
function toDomain(doc) {
|
|
7
|
+
return event_1.Event.create({
|
|
8
|
+
eventId: doc.eventId,
|
|
9
|
+
groupId: doc.groupId,
|
|
10
|
+
messageId: doc.messageId,
|
|
11
|
+
templateId: doc.templateId,
|
|
12
|
+
date: doc.date,
|
|
13
|
+
participants: doc.participants,
|
|
14
|
+
teams: doc.teams,
|
|
15
|
+
matches: doc.matches,
|
|
16
|
+
createdBy: doc.createdBy,
|
|
17
|
+
isRatingApplied: doc.isRatingApplied,
|
|
18
|
+
seasonName: doc.seasonName,
|
|
19
|
+
reportMessageId: doc.reportMessageId,
|
|
20
|
+
status: doc.status,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
function toDoc(event) {
|
|
24
|
+
return {
|
|
25
|
+
eventId: event.getEventId(),
|
|
26
|
+
groupId: event.getGroupId(),
|
|
27
|
+
messageId: event.getMessageId(),
|
|
28
|
+
templateId: event.getTemplateId(),
|
|
29
|
+
date: event.getDate(),
|
|
30
|
+
createdBy: event.getCreatedBy(),
|
|
31
|
+
participants: event.getParticipants(),
|
|
32
|
+
teams: event.getTeams(),
|
|
33
|
+
matches: event.getMatches(),
|
|
34
|
+
status: event.getStatus(),
|
|
35
|
+
seasonName: event.getSeasonName(),
|
|
36
|
+
isRatingApplied: event.getIsRatingApplied(),
|
|
37
|
+
reportMessageId: event.getReportMessageId(),
|
|
38
|
+
};
|
|
40
39
|
}
|
|
41
|
-
exports.EventMapper = EventMapper;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import type { Model } from "mongoose";
|
|
2
|
-
import type { EventsRepository
|
|
2
|
+
import type { EventsRepository } from "../../ports/events.repository";
|
|
3
3
|
import type { EventDoc } from "../../mongo";
|
|
4
4
|
import { Event } from "../../domain/event";
|
|
5
5
|
export declare class MongoEventsRepository implements EventsRepository {
|
|
6
6
|
private readonly EventModel;
|
|
7
7
|
constructor(EventModel: Model<EventDoc>);
|
|
8
|
-
create(
|
|
8
|
+
create(event: Event): Promise<Event>;
|
|
9
9
|
findById(eventId: number): Promise<Event | null>;
|
|
10
10
|
findByGroupAndStatuses(groupId: number, statuses: string[]): Promise<Event | null>;
|
|
11
11
|
findByTemplateAndGroup(templateId: number, groupId: number): Promise<Event | null>;
|
|
12
|
-
update(eventId: number, updates:
|
|
12
|
+
update(eventId: number, updates: Event): Promise<Event | null>;
|
|
13
13
|
findLastByGroup(groupId: number): Promise<Event | null>;
|
|
14
14
|
findAllByGroup(groupId: number): Promise<Event[]>;
|
|
15
15
|
countEvents(): Promise<number>;
|
|
@@ -6,34 +6,35 @@ class MongoEventsRepository {
|
|
|
6
6
|
constructor(EventModel) {
|
|
7
7
|
this.EventModel = EventModel;
|
|
8
8
|
}
|
|
9
|
-
async create(
|
|
10
|
-
const
|
|
11
|
-
const saved = await
|
|
12
|
-
return event_mapper_1.
|
|
9
|
+
async create(event) {
|
|
10
|
+
const write = (0, event_mapper_1.toDoc)(event);
|
|
11
|
+
const saved = await new this.EventModel(write).save();
|
|
12
|
+
return (0, event_mapper_1.toDomain)(saved.toObject());
|
|
13
13
|
}
|
|
14
14
|
async findById(eventId) {
|
|
15
15
|
const doc = await this.EventModel.findOne({ eventId }).lean();
|
|
16
|
-
return doc ? event_mapper_1.
|
|
16
|
+
return doc ? (0, event_mapper_1.toDomain)(doc) : null;
|
|
17
17
|
}
|
|
18
18
|
async findByGroupAndStatuses(groupId, statuses) {
|
|
19
19
|
const doc = await this.EventModel.findOne({ groupId, status: { $in: statuses } }).lean();
|
|
20
|
-
return doc ? event_mapper_1.
|
|
20
|
+
return doc ? (0, event_mapper_1.toDomain)(doc) : null;
|
|
21
21
|
}
|
|
22
22
|
async findByTemplateAndGroup(templateId, groupId) {
|
|
23
23
|
const doc = await this.EventModel.findOne({ templateId, groupId, status: "active" }).lean();
|
|
24
|
-
return doc ? event_mapper_1.
|
|
24
|
+
return doc ? (0, event_mapper_1.toDomain)(doc) : null;
|
|
25
25
|
}
|
|
26
26
|
async update(eventId, updates) {
|
|
27
|
-
const
|
|
28
|
-
|
|
27
|
+
const write = (0, event_mapper_1.toDoc)(updates);
|
|
28
|
+
const doc = await this.EventModel.findOneAndUpdate({ eventId }, { $set: write }, { new: true }).lean();
|
|
29
|
+
return doc ? (0, event_mapper_1.toDomain)(doc) : null;
|
|
29
30
|
}
|
|
30
31
|
async findLastByGroup(groupId) {
|
|
31
32
|
const doc = await this.EventModel.findOne({ groupId }).sort({ date: -1 }).lean();
|
|
32
|
-
return doc ? event_mapper_1.
|
|
33
|
+
return doc ? (0, event_mapper_1.toDomain)(doc) : null;
|
|
33
34
|
}
|
|
34
35
|
async findAllByGroup(groupId) {
|
|
35
36
|
const docs = await this.EventModel.find({ groupId }).lean();
|
|
36
|
-
return docs.map(d => event_mapper_1.
|
|
37
|
+
return docs.map(d => (0, event_mapper_1.toDomain)(d));
|
|
37
38
|
}
|
|
38
39
|
async countEvents() {
|
|
39
40
|
return this.EventModel.countDocuments();
|
|
@@ -47,7 +48,7 @@ class MongoEventsRepository {
|
|
|
47
48
|
}
|
|
48
49
|
async getAll() {
|
|
49
50
|
const docs = await this.EventModel.find().lean();
|
|
50
|
-
return docs.map(d => event_mapper_1.
|
|
51
|
+
return docs.map(d => (0, event_mapper_1.toDomain)(d));
|
|
51
52
|
}
|
|
52
53
|
}
|
|
53
54
|
exports.MongoEventsRepository = MongoEventsRepository;
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { Group } from "../../domain/group";
|
|
2
2
|
import { GroupDoc } from "../../mongo";
|
|
3
3
|
import { GroupWrite } from "../../ports/groups.repository";
|
|
4
|
-
export declare
|
|
5
|
-
|
|
6
|
-
static toDoc(group: Group): Partial<GroupWrite>;
|
|
7
|
-
}
|
|
4
|
+
export declare function toDomain(doc: GroupDoc): Group;
|
|
5
|
+
export declare function toDoc(group: Group): GroupWrite;
|
|
@@ -1,25 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.toDomain = toDomain;
|
|
4
|
+
exports.toDoc = toDoc;
|
|
4
5
|
const group_1 = require("../../domain/group");
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
};
|
|
23
|
-
}
|
|
6
|
+
function toDomain(doc) {
|
|
7
|
+
return group_1.Group.create({
|
|
8
|
+
groupId: doc.groupId,
|
|
9
|
+
groupName: doc.groupName,
|
|
10
|
+
participants: doc.participants,
|
|
11
|
+
timezone: doc.timezone,
|
|
12
|
+
isMessageLast: doc.isMessageLast,
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
function toDoc(group) {
|
|
16
|
+
return {
|
|
17
|
+
groupId: group.getGroupId(),
|
|
18
|
+
groupName: group.getGroupName(),
|
|
19
|
+
participants: group.getParticipants(),
|
|
20
|
+
timezone: group.getTimezone(),
|
|
21
|
+
isMessageLast: group.getIsMessageLast(),
|
|
22
|
+
};
|
|
24
23
|
}
|
|
25
|
-
exports.GroupMapper = GroupMapper;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import type { Model } from "mongoose";
|
|
2
|
-
import type { GroupsRepository
|
|
2
|
+
import type { GroupsRepository } from "../../ports/groups.repository";
|
|
3
3
|
import type { GroupDoc } from "../../mongo";
|
|
4
4
|
import { Group } from "../../domain/group";
|
|
5
5
|
export declare class MongoGroupsRepository implements GroupsRepository {
|
|
6
6
|
private readonly GroupModel;
|
|
7
7
|
constructor(GroupModel: Model<GroupDoc>);
|
|
8
|
-
create(
|
|
8
|
+
create(group: Group): Promise<Group>;
|
|
9
9
|
findById(groupId: number): Promise<Group | null>;
|
|
10
|
-
update(groupId: number, updates:
|
|
10
|
+
update(groupId: number, updates: Group): Promise<Group | null>;
|
|
11
11
|
findAll(): Promise<Group[]>;
|
|
12
12
|
delete(groupId: number): Promise<void>;
|
|
13
13
|
}
|
|
@@ -6,22 +6,23 @@ class MongoGroupsRepository {
|
|
|
6
6
|
constructor(GroupModel) {
|
|
7
7
|
this.GroupModel = GroupModel;
|
|
8
8
|
}
|
|
9
|
-
async create(
|
|
10
|
-
const
|
|
11
|
-
const saved = await
|
|
12
|
-
return group_mapper_1.
|
|
9
|
+
async create(group) {
|
|
10
|
+
const write = (0, group_mapper_1.toDoc)(group);
|
|
11
|
+
const saved = await new this.GroupModel(write).save();
|
|
12
|
+
return (0, group_mapper_1.toDomain)(saved.toObject());
|
|
13
13
|
}
|
|
14
14
|
async findById(groupId) {
|
|
15
15
|
const doc = await this.GroupModel.findOne({ groupId }).lean();
|
|
16
|
-
return doc ? group_mapper_1.
|
|
16
|
+
return doc ? (0, group_mapper_1.toDomain)(doc) : null;
|
|
17
17
|
}
|
|
18
18
|
async update(groupId, updates) {
|
|
19
|
-
const
|
|
20
|
-
|
|
19
|
+
const write = (0, group_mapper_1.toDoc)(updates);
|
|
20
|
+
const doc = await this.GroupModel.findOneAndUpdate({ groupId }, { $set: write }, { new: true }).lean();
|
|
21
|
+
return doc ? (0, group_mapper_1.toDomain)(doc) : null;
|
|
21
22
|
}
|
|
22
23
|
async findAll() {
|
|
23
24
|
const docs = await this.GroupModel.find().lean();
|
|
24
|
-
return docs.map((doc) => group_mapper_1.
|
|
25
|
+
return docs.map((doc) => (0, group_mapper_1.toDomain)(doc));
|
|
25
26
|
}
|
|
26
27
|
async delete(groupId) {
|
|
27
28
|
await this.GroupModel.deleteOne({ groupId });
|
|
@@ -1,9 +1,4 @@
|
|
|
1
1
|
import { User } from "../../domain/user";
|
|
2
2
|
import { UserDoc } from "../../mongo";
|
|
3
3
|
export declare function toDomain(doc: UserDoc): User;
|
|
4
|
-
export declare function toDoc(user: User):
|
|
5
|
-
firstName: string;
|
|
6
|
-
username: string | undefined;
|
|
7
|
-
userId: number;
|
|
8
|
-
language: import("../..").LanguageType;
|
|
9
|
-
};
|
|
4
|
+
export declare function toDoc(user: User): UserDoc;
|