@eliasrrosa/tutorhub-public-assets 0.0.22 → 0.1.0
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/application/helpers/helpers/filterAsync.d.ts +1 -0
- package/dist/application/helpers/helpers/filterAsync.js +18 -0
- package/dist/application/helpers/helpers/filterAsync.test.d.ts +1 -0
- package/dist/application/helpers/helpers/filterAsync.test.js +21 -0
- package/dist/application/helpers/helpers/tryCatch.d.ts +2 -0
- package/dist/application/helpers/helpers/tryCatch.js +31 -0
- package/dist/application/helpers/helpers/tryCatch.test.d.ts +1 -0
- package/dist/application/helpers/helpers/tryCatch.test.js +48 -0
- package/dist/domain/entities/Class.d.ts +10 -70
- package/dist/domain/entities/Class.js +0 -28
- package/dist/domain/entities/Class.test.d.ts +1 -0
- package/dist/domain/entities/Class.test.js +64 -0
- package/dist/domain/entities/ClassStatus.d.ts +4 -0
- package/dist/domain/entities/ClassStatus.js +2 -0
- package/dist/domain/entities/DateValidator.d.ts +1 -0
- package/dist/domain/entities/ISO8601Date.js +6 -1
- package/dist/domain/entities/ISO8601Date.test.js +8 -1
- package/dist/domain/entities/ISO8601DateTime.d.ts +2 -4
- package/dist/domain/entities/ISO8601DateValidator.d.ts +1 -0
- package/dist/domain/entities/ISO8601DateValidator.js +8 -1
- package/dist/domain/entities/ISO8601DateValidator.test.js +5 -1
- package/dist/domain/types/Class.d.ts +2 -0
- package/dist/domain/types/Class.js +5 -0
- package/dist/index.cjs +65 -34
- package/dist/index.d.ts +5 -2
- package/dist/index.js +62 -32
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function filterAsync<T>(arr: T[], predicate: (item: T) => Promise<boolean>): Promise<T[]>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.filterAsync = filterAsync;
|
|
13
|
+
function filterAsync(arr, predicate) {
|
|
14
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
15
|
+
const results = yield Promise.all(arr.map(predicate));
|
|
16
|
+
return arr.filter((_v, index) => results[index]);
|
|
17
|
+
});
|
|
18
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const filterAsync_1 = require("./filterAsync");
|
|
13
|
+
describe("filterAsync", () => {
|
|
14
|
+
it("Should filter accepting async operations.", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
15
|
+
const numbers = [1, 2, 3];
|
|
16
|
+
const filteredNumbers = yield (0, filterAsync_1.filterAsync)(numbers, (number) => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
|
+
return number > 1;
|
|
18
|
+
}));
|
|
19
|
+
expect(filteredNumbers).toEqual([2, 3]);
|
|
20
|
+
}));
|
|
21
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.tryCatch = tryCatch;
|
|
13
|
+
exports.tryCatchAsync = tryCatchAsync;
|
|
14
|
+
function tryCatch(callback, fallback) {
|
|
15
|
+
try {
|
|
16
|
+
return callback();
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
return fallback(error);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function tryCatchAsync(callback, fallback) {
|
|
23
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
try {
|
|
25
|
+
return yield callback();
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
return yield fallback(error);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const tryCatch_1 = require("./tryCatch");
|
|
13
|
+
describe("tryCatch", () => {
|
|
14
|
+
it("Should return try return value if success.", () => {
|
|
15
|
+
const a = (0, tryCatch_1.tryCatch)(() => {
|
|
16
|
+
return "abc";
|
|
17
|
+
}, () => {
|
|
18
|
+
return new Error("Trycatch failed.");
|
|
19
|
+
});
|
|
20
|
+
expect(a).toEqual("abc");
|
|
21
|
+
});
|
|
22
|
+
it("Should return catch return value if error.", () => {
|
|
23
|
+
const a = (0, tryCatch_1.tryCatch)(() => {
|
|
24
|
+
throw new Error("Error!");
|
|
25
|
+
}, () => {
|
|
26
|
+
return new Error("Trycatch failed.");
|
|
27
|
+
});
|
|
28
|
+
expect(a).toBeInstanceOf(Error);
|
|
29
|
+
expect(a.message).toEqual("Trycatch failed.");
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
describe("tryCatchAsync", () => {
|
|
33
|
+
it("Should return try return value if success.", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
34
|
+
const a = yield (0, tryCatch_1.tryCatchAsync)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
35
|
+
return "abc";
|
|
36
|
+
}), () => __awaiter(void 0, void 0, void 0, function* () { return new Error(); }));
|
|
37
|
+
expect(a).toEqual("abc");
|
|
38
|
+
}));
|
|
39
|
+
it("Should return catch return value if error.", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
40
|
+
const a = yield (0, tryCatch_1.tryCatchAsync)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
41
|
+
throw new Error("Error!");
|
|
42
|
+
}), () => __awaiter(void 0, void 0, void 0, function* () {
|
|
43
|
+
return new Error("Trycatch failed.");
|
|
44
|
+
}));
|
|
45
|
+
expect(a).toBeInstanceOf(Error);
|
|
46
|
+
expect(a.message).toEqual("Trycatch failed.");
|
|
47
|
+
}));
|
|
48
|
+
});
|
|
@@ -1,80 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ICourse } from "./Course";
|
|
1
|
+
import { IClassStatus } from "./ClassStatus";
|
|
3
2
|
import { IDate } from "./Date";
|
|
4
|
-
import { IFile } from "./File";
|
|
5
|
-
import { IGoogleCalendarEvent } from "./GoogleCalendarEvent";
|
|
6
|
-
import { IPayment } from "./Payment";
|
|
7
|
-
import { IRescheduleRequest } from "./RescheduleRequest";
|
|
8
3
|
import { ITime } from "./Time";
|
|
9
4
|
export interface IClass {
|
|
10
5
|
id: string;
|
|
11
|
-
groupId: string | null;
|
|
12
6
|
title: string;
|
|
13
|
-
description: string | null;
|
|
14
|
-
createdAt: Date | null;
|
|
15
|
-
updatedAt: Date | null;
|
|
16
7
|
date: IDate;
|
|
17
|
-
|
|
8
|
+
startTime: ITime;
|
|
18
9
|
endTime: ITime;
|
|
19
|
-
endDate: IDate | null;
|
|
20
10
|
courseId: string;
|
|
21
|
-
paymentId: string | null;
|
|
22
|
-
status: string | null;
|
|
23
|
-
course?: ICourse;
|
|
24
|
-
payment?: IPayment;
|
|
25
|
-
files?: IFile[];
|
|
26
|
-
rescheduleRequests?: IRescheduleRequest[];
|
|
27
|
-
googleCalendarEvents?: IGoogleCalendarEvent[];
|
|
28
|
-
meetingLink: string | null;
|
|
29
|
-
contractId: string | null;
|
|
30
|
-
contract?: IContract;
|
|
31
11
|
ownerId: string;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
date: IDate;
|
|
41
|
-
time: ITime;
|
|
42
|
-
endTime: ITime;
|
|
43
|
-
endDate: IDate | null;
|
|
44
|
-
courseId: string;
|
|
45
|
-
paymentId: string | null;
|
|
46
|
-
status: string | null;
|
|
47
|
-
course?: ICourse;
|
|
48
|
-
payment?: IPayment;
|
|
49
|
-
files?: IFile[];
|
|
50
|
-
rescheduleRequests?: IRescheduleRequest[];
|
|
51
|
-
googleCalendarEvents?: IGoogleCalendarEvent[];
|
|
52
|
-
meetingLink: string | null;
|
|
53
|
-
contractId: string | null;
|
|
54
|
-
contract?: IContract;
|
|
55
|
-
ownerId: string;
|
|
56
|
-
constructor(params: {
|
|
57
|
-
id: string;
|
|
58
|
-
groupId?: string | null;
|
|
59
|
-
title: string;
|
|
60
|
-
description?: string | null;
|
|
61
|
-
createdAt?: Date | null;
|
|
62
|
-
updatedAt?: Date | null;
|
|
63
|
-
date: IDate;
|
|
64
|
-
time: ITime;
|
|
65
|
-
endTime: ITime;
|
|
66
|
-
endDate?: IDate | null;
|
|
67
|
-
courseId: string;
|
|
68
|
-
paymentId?: string | null;
|
|
69
|
-
status?: string | null;
|
|
70
|
-
course?: ICourse;
|
|
71
|
-
payment?: IPayment;
|
|
72
|
-
files?: IFile[];
|
|
73
|
-
rescheduleRequests?: IRescheduleRequest[];
|
|
74
|
-
googleCalendarEvents?: IGoogleCalendarEvent[];
|
|
75
|
-
meetingLink?: string | null;
|
|
76
|
-
contractId?: string | null;
|
|
77
|
-
contract?: IContract;
|
|
78
|
-
ownerId: string;
|
|
79
|
-
});
|
|
12
|
+
status: IClassStatus;
|
|
13
|
+
groupId?: string;
|
|
14
|
+
description?: string;
|
|
15
|
+
createdAt?: Date;
|
|
16
|
+
updatedAt?: Date;
|
|
17
|
+
paymentId?: string;
|
|
18
|
+
meetingLink?: string;
|
|
19
|
+
contractId?: string;
|
|
80
20
|
}
|
|
@@ -1,30 +1,2 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Class = void 0;
|
|
4
|
-
class Class {
|
|
5
|
-
constructor(params) {
|
|
6
|
-
this.id = params.id;
|
|
7
|
-
this.groupId = params.groupId ? params.groupId : null;
|
|
8
|
-
this.title = params.title;
|
|
9
|
-
this.description = params.description ? params.description : null;
|
|
10
|
-
this.createdAt = params.createdAt ? params.createdAt : null;
|
|
11
|
-
this.updatedAt = params.updatedAt ? params.updatedAt : null;
|
|
12
|
-
this.date = params.date;
|
|
13
|
-
this.time = params.time;
|
|
14
|
-
this.endTime = params.endTime;
|
|
15
|
-
this.endDate = params.endDate ? params.endDate : null;
|
|
16
|
-
this.courseId = params.courseId;
|
|
17
|
-
this.paymentId = params.paymentId ? params.paymentId : null;
|
|
18
|
-
this.status = params.status ? params.status : null;
|
|
19
|
-
this.course = params.course;
|
|
20
|
-
this.payment = params.payment;
|
|
21
|
-
this.files = params.files;
|
|
22
|
-
this.rescheduleRequests = params.rescheduleRequests;
|
|
23
|
-
this.googleCalendarEvents = params.googleCalendarEvents;
|
|
24
|
-
this.meetingLink = params.meetingLink ? params.meetingLink : null;
|
|
25
|
-
this.contractId = params.contractId ? params.contractId : null;
|
|
26
|
-
this.contract = params.contract;
|
|
27
|
-
this.ownerId = params.ownerId;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
exports.Class = Class;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const Class_1 = require("./Class");
|
|
4
|
+
describe("Class", () => {
|
|
5
|
+
describe("Class constructor", () => {
|
|
6
|
+
const classData = {
|
|
7
|
+
id: "id",
|
|
8
|
+
title: "title",
|
|
9
|
+
date: "2025-01-01",
|
|
10
|
+
startTime: "12:00:00+03:00",
|
|
11
|
+
endTime: "13:00:00+03:00",
|
|
12
|
+
courseId: "courseId",
|
|
13
|
+
ownerId: "ownerId",
|
|
14
|
+
status: "pending",
|
|
15
|
+
updatedAt: "2025-01-01T00:00:00Z",
|
|
16
|
+
createdAt: "2025-01-01T00:00:00Z",
|
|
17
|
+
groupId: "groupId",
|
|
18
|
+
description: "description",
|
|
19
|
+
paymentId: "paymentId",
|
|
20
|
+
meetingLink: "meetingLink",
|
|
21
|
+
contractId: "contractId",
|
|
22
|
+
};
|
|
23
|
+
it("Should not throw given correct arguments", () => {
|
|
24
|
+
const aClass = () => new Class_1.Class(classData);
|
|
25
|
+
expect(aClass).not.toThrow();
|
|
26
|
+
});
|
|
27
|
+
it("Should throw given incorrect startTime format", () => {
|
|
28
|
+
const aClass = () => new Class_1.Class(Object.assign(Object.assign({}, classData), { startTime: "12" }));
|
|
29
|
+
expect(aClass).toThrow();
|
|
30
|
+
});
|
|
31
|
+
it("Should throw given incorrect endTime format", () => {
|
|
32
|
+
const aClass = () => new Class_1.Class(Object.assign(Object.assign({}, classData), { endTime: "24:00:00" }));
|
|
33
|
+
expect(aClass).toThrow();
|
|
34
|
+
});
|
|
35
|
+
it("Should throw given startTime greater than endTime", () => {
|
|
36
|
+
const aClass = () => new Class_1.Class(Object.assign(Object.assign({}, classData), { startTime: "12:00:00", endTime: "11:59:00" }));
|
|
37
|
+
expect(aClass).toThrow();
|
|
38
|
+
});
|
|
39
|
+
it("Should throw given startTime equal to endTime", () => {
|
|
40
|
+
const aClass = () => new Class_1.Class(Object.assign(Object.assign({}, classData), { startTime: "12:00:00", endTime: "12:00:00" }));
|
|
41
|
+
expect(aClass).toThrow();
|
|
42
|
+
});
|
|
43
|
+
it("Should throw given invalid status", () => {
|
|
44
|
+
const aClass = () => new Class_1.Class(Object.assign(Object.assign({}, classData), { status: "invalid status" }));
|
|
45
|
+
expect(aClass).toThrow();
|
|
46
|
+
});
|
|
47
|
+
it("Should throw given empty title", () => {
|
|
48
|
+
const aClass = () => new Class_1.Class(Object.assign(Object.assign({}, classData), { title: "" }));
|
|
49
|
+
expect(aClass).toThrow();
|
|
50
|
+
});
|
|
51
|
+
it("Should throw given incorrect date format", () => {
|
|
52
|
+
const aClass = () => new Class_1.Class(Object.assign(Object.assign({}, classData), { date: "2025-13-01" }));
|
|
53
|
+
expect(aClass).toThrow();
|
|
54
|
+
});
|
|
55
|
+
it("Should not throw given date with time and timezone", () => {
|
|
56
|
+
const aClass = () => new Class_1.Class(Object.assign(Object.assign({}, classData), { date: "2025-02-01T00:00:00Z" }));
|
|
57
|
+
expect(aClass).not.toThrow();
|
|
58
|
+
});
|
|
59
|
+
it("Should throw given createdAt greater than updatedAt", () => {
|
|
60
|
+
const aClass = () => new Class_1.Class(Object.assign(Object.assign({}, classData), { createdAt: "2025-01-02", updatedAt: "2025-01-01" }));
|
|
61
|
+
expect(aClass).toThrow();
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
});
|
|
@@ -49,7 +49,12 @@ class ISO8601Date {
|
|
|
49
49
|
const targetDate = date || this;
|
|
50
50
|
return targetDate.toUtcJsDateTime().getUTCDay();
|
|
51
51
|
};
|
|
52
|
-
|
|
52
|
+
const normalizedValue = value
|
|
53
|
+
? this.validator.match(value)
|
|
54
|
+
: this.getToday();
|
|
55
|
+
if (!normalizedValue)
|
|
56
|
+
throw new Error("Date format is invalid.");
|
|
57
|
+
this.value = normalizedValue;
|
|
53
58
|
this.throwIfFormatIsNotValid();
|
|
54
59
|
}
|
|
55
60
|
throwIfFormatIsNotValid() {
|
|
@@ -15,10 +15,17 @@ describe("ISO8601Date", () => {
|
|
|
15
15
|
});
|
|
16
16
|
it("Should throw if value is not valid", () => {
|
|
17
17
|
const instantiateDate = () => {
|
|
18
|
-
new ISO8601Date_1.ISO8601Date("2025-01-
|
|
18
|
+
new ISO8601Date_1.ISO8601Date("2025-01-m");
|
|
19
19
|
};
|
|
20
20
|
expect(instantiateDate).toThrow();
|
|
21
21
|
});
|
|
22
|
+
it("Should throw if value contains timezone or other strings", () => {
|
|
23
|
+
const instantiateDate = () => {
|
|
24
|
+
return new ISO8601Date_1.ISO8601Date("2025-01-01T00:00:00Z");
|
|
25
|
+
};
|
|
26
|
+
expect(instantiateDate).not.toThrow();
|
|
27
|
+
expect(instantiateDate().value).toEqual("2025-01-01");
|
|
28
|
+
});
|
|
22
29
|
it("Should construct with no arguments.", () => {
|
|
23
30
|
const date = new ISO8601Date_1.ISO8601Date();
|
|
24
31
|
expect(date).toBeDefined();
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { IDate } from "./Date";
|
|
2
2
|
import { ITime } from "./Time";
|
|
3
3
|
export interface IDateTime {
|
|
4
|
-
date: IDate;
|
|
5
|
-
time: ITime;
|
|
6
4
|
getJSDateTime: () => Date;
|
|
7
5
|
/**
|
|
8
6
|
* Returns DateTime string with added Brazilian timezone (-03:00) without converting the date or time.
|
|
@@ -25,8 +23,8 @@ export interface IDateTime {
|
|
|
25
23
|
}) => string;
|
|
26
24
|
}
|
|
27
25
|
export declare class ISO8601DateTime implements IDateTime {
|
|
28
|
-
date
|
|
29
|
-
time
|
|
26
|
+
private date;
|
|
27
|
+
private time;
|
|
30
28
|
constructor(opts: {
|
|
31
29
|
date: IDate;
|
|
32
30
|
time: ITime;
|
|
@@ -8,7 +8,7 @@ exports.ISO8601DateValidator = void 0;
|
|
|
8
8
|
*/
|
|
9
9
|
class ISO8601DateValidator {
|
|
10
10
|
constructor() {
|
|
11
|
-
this.YYYYmmDD = new RegExp("^[0-9]{4}-([0][1-9]|[1][0-2])-([0][1-9]|[1-2][0-9]|[3][0-1])
|
|
11
|
+
this.YYYYmmDD = new RegExp("^[0-9]{4}-([0][1-9]|[1][0-2])-([0][1-9]|[1-2][0-9]|[3][0-1])");
|
|
12
12
|
}
|
|
13
13
|
/**
|
|
14
14
|
* Accepted format: YYYY-MM-DD
|
|
@@ -16,5 +16,12 @@ class ISO8601DateValidator {
|
|
|
16
16
|
formatIsValid(date) {
|
|
17
17
|
return this.YYYYmmDD.test(date);
|
|
18
18
|
}
|
|
19
|
+
match(date) {
|
|
20
|
+
const matches = date.match(this.YYYYmmDD);
|
|
21
|
+
if (!matches || matches.length < 1) {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
return matches[0];
|
|
25
|
+
}
|
|
19
26
|
}
|
|
20
27
|
exports.ISO8601DateValidator = ISO8601DateValidator;
|
|
@@ -7,9 +7,13 @@ describe("ISO8601DateValidator", () => {
|
|
|
7
7
|
const date = new ISO8601DateValidator_1.ISO8601DateValidator();
|
|
8
8
|
expect(date.formatIsValid("2025-01-01")).toBe(true);
|
|
9
9
|
});
|
|
10
|
+
it("Should return true if format is YYYY-MM-DD but has more characters.", () => {
|
|
11
|
+
const date = new ISO8601DateValidator_1.ISO8601DateValidator();
|
|
12
|
+
expect(date.formatIsValid("2025-01-01T00:00:00Z")).toBe(true);
|
|
13
|
+
});
|
|
10
14
|
it("Should return false if format is not YYYY-MM-DD.", () => {
|
|
11
15
|
const date = new ISO8601DateValidator_1.ISO8601DateValidator();
|
|
12
|
-
expect(date.formatIsValid("2025-01-
|
|
16
|
+
expect(date.formatIsValid("2025-01-m")).toBe(false);
|
|
13
17
|
});
|
|
14
18
|
});
|
|
15
19
|
});
|
package/dist/index.cjs
CHANGED
|
@@ -16,12 +16,31 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var __async = (__this, __arguments, generator) => {
|
|
20
|
+
return new Promise((resolve, reject) => {
|
|
21
|
+
var fulfilled = (value) => {
|
|
22
|
+
try {
|
|
23
|
+
step(generator.next(value));
|
|
24
|
+
} catch (e) {
|
|
25
|
+
reject(e);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
var rejected = (value) => {
|
|
29
|
+
try {
|
|
30
|
+
step(generator.throw(value));
|
|
31
|
+
} catch (e) {
|
|
32
|
+
reject(e);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
36
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
37
|
+
});
|
|
38
|
+
};
|
|
19
39
|
|
|
20
40
|
// src/index.ts
|
|
21
41
|
var index_exports = {};
|
|
22
42
|
__export(index_exports, {
|
|
23
43
|
AsaasCustomer: () => AsaasCustomer,
|
|
24
|
-
Class: () => Class,
|
|
25
44
|
ClassCreationFormSchema: () => ClassCreationFormSchema,
|
|
26
45
|
ClassCreationRecurrenceRuleSchema: () => ClassCreationRecurrenceRuleSchema,
|
|
27
46
|
ClassStatusSchema: () => ClassStatusSchema,
|
|
@@ -31,7 +50,10 @@ __export(index_exports, {
|
|
|
31
50
|
ISO8601DateValidator: () => ISO8601DateValidator,
|
|
32
51
|
ISO8601Time: () => ISO8601Time,
|
|
33
52
|
ISO8601TimeValidator: () => ISO8601TimeValidator,
|
|
34
|
-
UserUnavailableTime: () => UserUnavailableTime
|
|
53
|
+
UserUnavailableTime: () => UserUnavailableTime,
|
|
54
|
+
filterAsync: () => filterAsync,
|
|
55
|
+
tryCatch: () => tryCatch,
|
|
56
|
+
tryCatchAsync: () => tryCatchAsync
|
|
35
57
|
});
|
|
36
58
|
module.exports = __toCommonJS(index_exports);
|
|
37
59
|
|
|
@@ -46,39 +68,11 @@ var AsaasCustomer = class {
|
|
|
46
68
|
}
|
|
47
69
|
};
|
|
48
70
|
|
|
49
|
-
// src/domain/entities/Class.ts
|
|
50
|
-
var Class = class {
|
|
51
|
-
constructor(params) {
|
|
52
|
-
this.id = params.id;
|
|
53
|
-
this.groupId = params.groupId ? params.groupId : null;
|
|
54
|
-
this.title = params.title;
|
|
55
|
-
this.description = params.description ? params.description : null;
|
|
56
|
-
this.createdAt = params.createdAt ? params.createdAt : null;
|
|
57
|
-
this.updatedAt = params.updatedAt ? params.updatedAt : null;
|
|
58
|
-
this.date = params.date;
|
|
59
|
-
this.time = params.time;
|
|
60
|
-
this.endTime = params.endTime;
|
|
61
|
-
this.endDate = params.endDate ? params.endDate : null;
|
|
62
|
-
this.courseId = params.courseId;
|
|
63
|
-
this.paymentId = params.paymentId ? params.paymentId : null;
|
|
64
|
-
this.status = params.status ? params.status : null;
|
|
65
|
-
this.course = params.course;
|
|
66
|
-
this.payment = params.payment;
|
|
67
|
-
this.files = params.files;
|
|
68
|
-
this.rescheduleRequests = params.rescheduleRequests;
|
|
69
|
-
this.googleCalendarEvents = params.googleCalendarEvents;
|
|
70
|
-
this.meetingLink = params.meetingLink ? params.meetingLink : null;
|
|
71
|
-
this.contractId = params.contractId ? params.contractId : null;
|
|
72
|
-
this.contract = params.contract;
|
|
73
|
-
this.ownerId = params.ownerId;
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
|
|
77
71
|
// src/domain/entities/ISO8601DateValidator.ts
|
|
78
72
|
var ISO8601DateValidator = class {
|
|
79
73
|
constructor() {
|
|
80
74
|
this.YYYYmmDD = new RegExp(
|
|
81
|
-
"^[0-9]{4}-([0][1-9]|[1][0-2])-([0][1-9]|[1-2][0-9]|[3][0-1])
|
|
75
|
+
"^[0-9]{4}-([0][1-9]|[1][0-2])-([0][1-9]|[1-2][0-9]|[3][0-1])"
|
|
82
76
|
);
|
|
83
77
|
}
|
|
84
78
|
/**
|
|
@@ -87,6 +81,13 @@ var ISO8601DateValidator = class {
|
|
|
87
81
|
formatIsValid(date) {
|
|
88
82
|
return this.YYYYmmDD.test(date);
|
|
89
83
|
}
|
|
84
|
+
match(date) {
|
|
85
|
+
const matches = date.match(this.YYYYmmDD);
|
|
86
|
+
if (!matches || matches.length < 1) {
|
|
87
|
+
return void 0;
|
|
88
|
+
}
|
|
89
|
+
return matches[0];
|
|
90
|
+
}
|
|
90
91
|
};
|
|
91
92
|
|
|
92
93
|
// src/domain/entities/ISO8601Date.ts
|
|
@@ -147,7 +148,9 @@ var _ISO8601Date = class _ISO8601Date {
|
|
|
147
148
|
const targetDate = date || this;
|
|
148
149
|
return targetDate.toUtcJsDateTime().getUTCDay();
|
|
149
150
|
};
|
|
150
|
-
|
|
151
|
+
const normalizedValue = value ? this.validator.match(value) : this.getToday();
|
|
152
|
+
if (!normalizedValue) throw new Error("Date format is invalid.");
|
|
153
|
+
this.value = normalizedValue;
|
|
151
154
|
this.throwIfFormatIsNotValid();
|
|
152
155
|
}
|
|
153
156
|
throwIfFormatIsNotValid() {
|
|
@@ -595,10 +598,35 @@ var FreeDateTimeSlot = class {
|
|
|
595
598
|
this.userId = opts.userId;
|
|
596
599
|
}
|
|
597
600
|
};
|
|
601
|
+
|
|
602
|
+
// src/application/helpers/helpers/tryCatch.ts
|
|
603
|
+
function tryCatch(callback, fallback) {
|
|
604
|
+
try {
|
|
605
|
+
return callback();
|
|
606
|
+
} catch (error) {
|
|
607
|
+
return fallback(error);
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
function tryCatchAsync(callback, fallback) {
|
|
611
|
+
return __async(this, null, function* () {
|
|
612
|
+
try {
|
|
613
|
+
return yield callback();
|
|
614
|
+
} catch (error) {
|
|
615
|
+
return yield fallback(error);
|
|
616
|
+
}
|
|
617
|
+
});
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
// src/application/helpers/helpers/filterAsync.ts
|
|
621
|
+
function filterAsync(arr, predicate) {
|
|
622
|
+
return __async(this, null, function* () {
|
|
623
|
+
const results = yield Promise.all(arr.map(predicate));
|
|
624
|
+
return arr.filter((_v, index) => results[index]);
|
|
625
|
+
});
|
|
626
|
+
}
|
|
598
627
|
// Annotate the CommonJS export names for ESM import in node:
|
|
599
628
|
0 && (module.exports = {
|
|
600
629
|
AsaasCustomer,
|
|
601
|
-
Class,
|
|
602
630
|
ClassCreationFormSchema,
|
|
603
631
|
ClassCreationRecurrenceRuleSchema,
|
|
604
632
|
ClassStatusSchema,
|
|
@@ -608,5 +636,8 @@ var FreeDateTimeSlot = class {
|
|
|
608
636
|
ISO8601DateValidator,
|
|
609
637
|
ISO8601Time,
|
|
610
638
|
ISO8601TimeValidator,
|
|
611
|
-
UserUnavailableTime
|
|
639
|
+
UserUnavailableTime,
|
|
640
|
+
filterAsync,
|
|
641
|
+
tryCatch,
|
|
642
|
+
tryCatchAsync
|
|
612
643
|
});
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AsaasCustomer } from "./domain/entities/AsaasCustomer.js";
|
|
2
|
-
import {
|
|
2
|
+
import { IClass } from "./domain/entities/Class.js";
|
|
3
3
|
import { IClassRequest } from "./domain/entities/ClassRequest.js";
|
|
4
4
|
import { IContract } from "./domain/entities/Contract.js";
|
|
5
5
|
import { ICourse } from "./domain/entities/Course.js";
|
|
@@ -46,6 +46,9 @@ import { GetFixedAvailableTimeResponseBody } from "./infrastructure/restful/resp
|
|
|
46
46
|
import { ClassCreationForm, ClassCreationFormSchema } from "./infrastructure/restful/requests/forms/ClassCreationForm.js";
|
|
47
47
|
import { ClassStatus, ClassStatusSchema } from "./domain/types/ClassStatus.js";
|
|
48
48
|
import { ClassCreationRecurrenceRule, ClassCreationRecurrenceRuleSchema } from "./domain/types/ClassCreationRecurrenceRule.js";
|
|
49
|
+
import { IClassStatus } from "./domain/entities/ClassStatus.js";
|
|
49
50
|
import { IUserUnavailableTime, UserUnavailableTime } from "./domain/entities/UserUnavailableTime.js";
|
|
50
51
|
import { IFreeDateTimeSlot, FreeDateTimeSlot } from "./domain/entities/FreeTimeSlot.js";
|
|
51
|
-
|
|
52
|
+
import { tryCatch, tryCatchAsync } from "./application/helpers/helpers/tryCatch.js";
|
|
53
|
+
import { filterAsync } from "./application/helpers/helpers/filterAsync.js";
|
|
54
|
+
export { filterAsync, tryCatchAsync, tryCatch, ClassStatus, AsaasCustomer, IClass, IClassRequest, IContract, ICourse, ICourseToSchoolConnectionRequest, IDate, IDateTimeSlot, IFreeDateTimeSlot, FreeDateTimeSlot, IUserUnavailableTime, UserUnavailableTime, IDateValidator, IFile, IGenericNotification, IGoogleAuth, IGoogleCalendar, IGoogleCalendarEvent, ISO8601Date, IDateTime, ISO8601DateValidator, ISO8601Time, ISO8601TimeValidator, IPasswordRecovery, IPayment, IPaymentRecognitionRequest, IPreApprovedUser, IRescheduleRequest, ISchool, ISchoolConnection, ISchoolConnectionRequest, ISchoolStudent, ISchoolTeacher, ITime, ITimeSlot, ITimeValidator, IUnauthorizedUser, IUserAuth, IUserConnection, IUserConnectionRequest, IUserCredentials, IUserNavigation, IUserPreferences, IUserPremium, IUserProfile, IUserRoles, IUserSharedFileTimestamps, IUnavailableTimeRepository, GetFixedAvailableTimeResponseBody, ISO8601DateTime, ClassCreationForm, ClassCreationRecurrenceRule, ClassCreationFormSchema, ClassCreationRecurrenceRuleSchema, ClassStatusSchema, IClassStatus };
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,24 @@
|
|
|
1
|
+
var __async = (__this, __arguments, generator) => {
|
|
2
|
+
return new Promise((resolve, reject) => {
|
|
3
|
+
var fulfilled = (value) => {
|
|
4
|
+
try {
|
|
5
|
+
step(generator.next(value));
|
|
6
|
+
} catch (e) {
|
|
7
|
+
reject(e);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
var rejected = (value) => {
|
|
11
|
+
try {
|
|
12
|
+
step(generator.throw(value));
|
|
13
|
+
} catch (e) {
|
|
14
|
+
reject(e);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
18
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
|
|
1
22
|
// src/domain/entities/AsaasCustomer.ts
|
|
2
23
|
var AsaasCustomer = class {
|
|
3
24
|
constructor(opts) {
|
|
@@ -9,39 +30,11 @@ var AsaasCustomer = class {
|
|
|
9
30
|
}
|
|
10
31
|
};
|
|
11
32
|
|
|
12
|
-
// src/domain/entities/Class.ts
|
|
13
|
-
var Class = class {
|
|
14
|
-
constructor(params) {
|
|
15
|
-
this.id = params.id;
|
|
16
|
-
this.groupId = params.groupId ? params.groupId : null;
|
|
17
|
-
this.title = params.title;
|
|
18
|
-
this.description = params.description ? params.description : null;
|
|
19
|
-
this.createdAt = params.createdAt ? params.createdAt : null;
|
|
20
|
-
this.updatedAt = params.updatedAt ? params.updatedAt : null;
|
|
21
|
-
this.date = params.date;
|
|
22
|
-
this.time = params.time;
|
|
23
|
-
this.endTime = params.endTime;
|
|
24
|
-
this.endDate = params.endDate ? params.endDate : null;
|
|
25
|
-
this.courseId = params.courseId;
|
|
26
|
-
this.paymentId = params.paymentId ? params.paymentId : null;
|
|
27
|
-
this.status = params.status ? params.status : null;
|
|
28
|
-
this.course = params.course;
|
|
29
|
-
this.payment = params.payment;
|
|
30
|
-
this.files = params.files;
|
|
31
|
-
this.rescheduleRequests = params.rescheduleRequests;
|
|
32
|
-
this.googleCalendarEvents = params.googleCalendarEvents;
|
|
33
|
-
this.meetingLink = params.meetingLink ? params.meetingLink : null;
|
|
34
|
-
this.contractId = params.contractId ? params.contractId : null;
|
|
35
|
-
this.contract = params.contract;
|
|
36
|
-
this.ownerId = params.ownerId;
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
|
|
40
33
|
// src/domain/entities/ISO8601DateValidator.ts
|
|
41
34
|
var ISO8601DateValidator = class {
|
|
42
35
|
constructor() {
|
|
43
36
|
this.YYYYmmDD = new RegExp(
|
|
44
|
-
"^[0-9]{4}-([0][1-9]|[1][0-2])-([0][1-9]|[1-2][0-9]|[3][0-1])
|
|
37
|
+
"^[0-9]{4}-([0][1-9]|[1][0-2])-([0][1-9]|[1-2][0-9]|[3][0-1])"
|
|
45
38
|
);
|
|
46
39
|
}
|
|
47
40
|
/**
|
|
@@ -50,6 +43,13 @@ var ISO8601DateValidator = class {
|
|
|
50
43
|
formatIsValid(date) {
|
|
51
44
|
return this.YYYYmmDD.test(date);
|
|
52
45
|
}
|
|
46
|
+
match(date) {
|
|
47
|
+
const matches = date.match(this.YYYYmmDD);
|
|
48
|
+
if (!matches || matches.length < 1) {
|
|
49
|
+
return void 0;
|
|
50
|
+
}
|
|
51
|
+
return matches[0];
|
|
52
|
+
}
|
|
53
53
|
};
|
|
54
54
|
|
|
55
55
|
// src/domain/entities/ISO8601Date.ts
|
|
@@ -110,7 +110,9 @@ var _ISO8601Date = class _ISO8601Date {
|
|
|
110
110
|
const targetDate = date || this;
|
|
111
111
|
return targetDate.toUtcJsDateTime().getUTCDay();
|
|
112
112
|
};
|
|
113
|
-
|
|
113
|
+
const normalizedValue = value ? this.validator.match(value) : this.getToday();
|
|
114
|
+
if (!normalizedValue) throw new Error("Date format is invalid.");
|
|
115
|
+
this.value = normalizedValue;
|
|
114
116
|
this.throwIfFormatIsNotValid();
|
|
115
117
|
}
|
|
116
118
|
throwIfFormatIsNotValid() {
|
|
@@ -558,9 +560,34 @@ var FreeDateTimeSlot = class {
|
|
|
558
560
|
this.userId = opts.userId;
|
|
559
561
|
}
|
|
560
562
|
};
|
|
563
|
+
|
|
564
|
+
// src/application/helpers/helpers/tryCatch.ts
|
|
565
|
+
function tryCatch(callback, fallback) {
|
|
566
|
+
try {
|
|
567
|
+
return callback();
|
|
568
|
+
} catch (error) {
|
|
569
|
+
return fallback(error);
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
function tryCatchAsync(callback, fallback) {
|
|
573
|
+
return __async(this, null, function* () {
|
|
574
|
+
try {
|
|
575
|
+
return yield callback();
|
|
576
|
+
} catch (error) {
|
|
577
|
+
return yield fallback(error);
|
|
578
|
+
}
|
|
579
|
+
});
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
// src/application/helpers/helpers/filterAsync.ts
|
|
583
|
+
function filterAsync(arr, predicate) {
|
|
584
|
+
return __async(this, null, function* () {
|
|
585
|
+
const results = yield Promise.all(arr.map(predicate));
|
|
586
|
+
return arr.filter((_v, index) => results[index]);
|
|
587
|
+
});
|
|
588
|
+
}
|
|
561
589
|
export {
|
|
562
590
|
AsaasCustomer,
|
|
563
|
-
Class,
|
|
564
591
|
ClassCreationFormSchema,
|
|
565
592
|
ClassCreationRecurrenceRuleSchema,
|
|
566
593
|
ClassStatusSchema,
|
|
@@ -570,5 +597,8 @@ export {
|
|
|
570
597
|
ISO8601DateValidator,
|
|
571
598
|
ISO8601Time,
|
|
572
599
|
ISO8601TimeValidator,
|
|
573
|
-
UserUnavailableTime
|
|
600
|
+
UserUnavailableTime,
|
|
601
|
+
filterAsync,
|
|
602
|
+
tryCatch,
|
|
603
|
+
tryCatchAsync
|
|
574
604
|
};
|