From 0f1e5722ce5685779ca3e3f89268e8329cbe7b2a Mon Sep 17 00:00:00 2001 From: OneLiL05 Date: Tue, 26 Sep 2023 19:44:21 +0200 Subject: [PATCH 1/6] feat: improve performance --- packages/nurekit/src/helpers/schedule.helper.ts | 15 +++++++++------ packages/nurekit/src/helpers/teachers.helper.ts | 12 ++++++++---- packages/nurekit/src/index.ts | 10 ++++++++++ 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/packages/nurekit/src/helpers/schedule.helper.ts b/packages/nurekit/src/helpers/schedule.helper.ts index afe6610..c3422da 100644 --- a/packages/nurekit/src/helpers/schedule.helper.ts +++ b/packages/nurekit/src/helpers/schedule.helper.ts @@ -2,17 +2,20 @@ import { IRawSchedule, ISchedule } from "../index.js"; import { transformTeachers } from "./teachers.helper.js"; export function transformSchedule(rawSchedule: IRawSchedule[]): ISchedule[] { - return rawSchedule.map((rawSchedule) => { - const { end_time, start_time, teachers, number_pair, auditory, ...rest } = - rawSchedule; + const transformedSchedule: ISchedule[] = []; - return { + for (let subject of rawSchedule) { + const { end_time, start_time, teachers, number_pair, auditory, ...rest } = subject; + + transformedSchedule.push({ ...rest, endTime: end_time, startTime: start_time, teachers: transformTeachers(teachers), numberPair: number_pair, auditorium: auditory, - }; - }); + }); + } + + return transformedSchedule; } diff --git a/packages/nurekit/src/helpers/teachers.helper.ts b/packages/nurekit/src/helpers/teachers.helper.ts index 2fb25e0..3b0f558 100644 --- a/packages/nurekit/src/helpers/teachers.helper.ts +++ b/packages/nurekit/src/helpers/teachers.helper.ts @@ -1,13 +1,17 @@ import { IRawTeacher, ITeacher } from "../types/index.js"; function transformTeachers(rawTeachers: IRawTeacher[]): ITeacher[] { - return rawTeachers.map((teacher) => { - return { + const transformedTeachers: ITeacher[] = [] + + for (let teacher of rawTeachers) { + transformedTeachers.push({ id: teacher.id, fullName: teacher.full_name, shortName: teacher.short_name, - }; - }); + }) + } + + return transformedTeachers; } export { transformTeachers }; diff --git a/packages/nurekit/src/index.ts b/packages/nurekit/src/index.ts index a832dc2..a384e04 100644 --- a/packages/nurekit/src/index.ts +++ b/packages/nurekit/src/index.ts @@ -1,2 +1,12 @@ +import { Nurekit } from "./client.js"; + export * from "./client.js"; export * from "./types/index.js"; + +const nurekit = new Nurekit() + +console.log(await nurekit.groups.getSchedule({ + groupName: "пзпі-23-5", + startTime: "2023-09-22", + endTime: "2023-09-23" +})) From 23d0cb318575e177d8274579cb664fabc1343014 Mon Sep 17 00:00:00 2001 From: OneLiL05 Date: Mon, 2 Oct 2023 18:33:31 +0300 Subject: [PATCH 2/6] refactor: move toTimestamp function to adapter's method --- packages/nurekit/src/adapters/timestamp.adapter.ts | 12 ++++++++---- packages/nurekit/src/helpers/date.helper.ts | 5 ----- 2 files changed, 8 insertions(+), 9 deletions(-) delete mode 100644 packages/nurekit/src/helpers/date.helper.ts diff --git a/packages/nurekit/src/adapters/timestamp.adapter.ts b/packages/nurekit/src/adapters/timestamp.adapter.ts index 00b0ad0..1198e4c 100644 --- a/packages/nurekit/src/adapters/timestamp.adapter.ts +++ b/packages/nurekit/src/adapters/timestamp.adapter.ts @@ -1,5 +1,3 @@ -import { toTimestamp } from "../helpers/date.helper.js"; - interface ConvertParams { startTime: string; endTime: string; @@ -13,8 +11,14 @@ interface IConvertedTime { export class TimestampAdapter { public convert({ startTime, endTime }: ConvertParams): IConvertedTime { return { - startTimestamp: toTimestamp(startTime), - endTimestamp: toTimestamp(endTime), + startTimestamp: this.#toTimestamp(startTime), + endTimestamp: this.#toTimestamp(endTime), }; } + + #toTimestamp(date: string) { + const parsedDate = Date.parse(date); + + return parsedDate / 1000; + } } diff --git a/packages/nurekit/src/helpers/date.helper.ts b/packages/nurekit/src/helpers/date.helper.ts deleted file mode 100644 index 050d58e..0000000 --- a/packages/nurekit/src/helpers/date.helper.ts +++ /dev/null @@ -1,5 +0,0 @@ -export function toTimestamp(stringDate: string) { - const parsedDate = Date.parse(stringDate); - - return parsedDate / 1000; -} From c153d23ea70cbfcd2d7b2c2c848d589e36dc0062 Mon Sep 17 00:00:00 2001 From: OneLiL05 Date: Mon, 2 Oct 2023 18:34:07 +0300 Subject: [PATCH 3/6] refactor: update exported types --- packages/nurekit/src/index.ts | 2 +- packages/nurekit/src/modules/groups.module.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/nurekit/src/index.ts b/packages/nurekit/src/index.ts index a384e04..69a2fb5 100644 --- a/packages/nurekit/src/index.ts +++ b/packages/nurekit/src/index.ts @@ -1,7 +1,7 @@ import { Nurekit } from "./client.js"; export * from "./client.js"; -export * from "./types/index.js"; +export { IAuditorium, IGroup, ISchedule, ISubject, ITeacher } from "./types/index.js"; const nurekit = new Nurekit() diff --git a/packages/nurekit/src/modules/groups.module.ts b/packages/nurekit/src/modules/groups.module.ts index a2a0a03..e40c066 100644 --- a/packages/nurekit/src/modules/groups.module.ts +++ b/packages/nurekit/src/modules/groups.module.ts @@ -1,7 +1,7 @@ import { TimestampAdapter } from "../adapters/timestamp.adapter.js"; import { handleAxiosError } from "../helpers/axios.helper.js"; import { transformSchedule } from "../helpers/schedule.helper.js"; -import { IGroup, IRawSchedule, ISchedule } from "../index.js"; +import { IGroup, IRawSchedule, ISchedule } from "../types/index.js"; import { axiosClient } from "../libs/axios.js"; interface GetScheduleParams { From 071375276f8714759271da2dedb427f73952cabf Mon Sep 17 00:00:00 2001 From: OneLiL05 Date: Mon, 2 Oct 2023 18:34:47 +0300 Subject: [PATCH 4/6] v0.2.3 --- packages/nurekit/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/nurekit/package.json b/packages/nurekit/package.json index 2e9ccb0..3799797 100644 --- a/packages/nurekit/package.json +++ b/packages/nurekit/package.json @@ -1,7 +1,7 @@ { "name": "@nurejs/api", "description": "Node.js client for Nure API", - "version": "0.2.2", + "version": "0.2.3", "keywords": [ "api", "nure", From 2bfc7d8e4bd7e5d3a5536a4f110c6a81d34204ad Mon Sep 17 00:00:00 2001 From: OneLiL05 Date: Mon, 2 Oct 2023 18:36:28 +0300 Subject: [PATCH 5/6] fix: update exported types --- packages/nurekit/src/helpers/schedule.helper.ts | 2 +- packages/nurekit/tsconfig.json | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/nurekit/src/helpers/schedule.helper.ts b/packages/nurekit/src/helpers/schedule.helper.ts index c3422da..bc448e0 100644 --- a/packages/nurekit/src/helpers/schedule.helper.ts +++ b/packages/nurekit/src/helpers/schedule.helper.ts @@ -1,4 +1,4 @@ -import { IRawSchedule, ISchedule } from "../index.js"; +import { IRawSchedule, ISchedule } from "../types/index.js"; import { transformTeachers } from "./teachers.helper.js"; export function transformSchedule(rawSchedule: IRawSchedule[]): ISchedule[] { diff --git a/packages/nurekit/tsconfig.json b/packages/nurekit/tsconfig.json index 0d670bf..f17dc0e 100644 --- a/packages/nurekit/tsconfig.json +++ b/packages/nurekit/tsconfig.json @@ -8,6 +8,7 @@ "outDir": "dist", "strict": true, "strictNullChecks": true, + "skipLibCheck": true }, "include": ["src"] } From f2947acca03d90a43d0b6302dd32ad5c3549a07c Mon Sep 17 00:00:00 2001 From: OneLiL05 Date: Mon, 2 Oct 2023 18:39:25 +0300 Subject: [PATCH 6/6] community: change README.md file --- README.md | 252 +----------------------------------------------------- 1 file changed, 4 insertions(+), 248 deletions(-) diff --git a/README.md b/README.md index cc7caba..6f4c42e 100644 --- a/README.md +++ b/README.md @@ -14,262 +14,18 @@ npm i @nurejs/api ## Usage ```js -import { Nurekit } from "@nurejs/api" +import { Nurekit } from "@nurejs/api"; -const nurekit = new Nurekit() +const nurekit = new Nurekit(); ``` ## Contributing If you want to contribute to improving the project, firstly read [CONTIRBUTING.md](https://github.com/OneLiL05/nurekit/blob/main/CONTRIBUTING.md) -## Methods +## Documetation -### Get auditoriums - -[Reference](https://nure-dev.pp.ua/#%D0%B7%D0%B0%D0%BF%D0%B8%D1%82-%D0%BD%D0%B0-%D0%B0%D1%83%D0%B4%D0%B8%D1%82%D0%BE%D1%80%D1%96%D1%97) - -**Example:** - -```js -import { Nurekit } from "@nurejs/api" - -const nurekit = new Nurekit() - -const auditories = await nurekit.auditoriums.findMany() -``` - -**Output:** - -```ts -{ - id: number; - name: string; -}[] -``` - -### Get auditorium - -```js -import { Nurekit } from "@nurejs/api" - -const nurekit = new Nurekit() - -const auditories = await nurekit.auditoriums.findOne("285") -``` - -**Input:** - -```ts -{ - name: string -} -``` - -**Output:** - -```ts -{ - id: number; - name: string; -} -``` - -### Get groups - -[Reference](https://nure-dev.pp.ua/#%D0%B7%D0%B0%D0%BF%D0%B8%D1%82-%D0%BD%D0%B0-%D0%B3%D1%80%D1%83%D0%BF%D0%B8) - -**Example:** - -```js -import { Nurekit } from "@nurejs/api" - -const nurekit = new Nurekit() - -const groups = await nurekit.groups.findMany() -``` - -**Output:** - -```ts -{ - id: number; - name: string; -}[] -``` - -### Get a group - -**Example:** - -```js -import { Nurekit } from "@nurejs/api" - -const nurekit = new Nurekit() - -const groups = await nurekit.groups.findOne("пзпі-23-5") -``` - -**Input:** - -```ts -{ - name: string -} -``` - -**Output:** - -```ts -{ - id: number; - name: string; -} -``` - -### Get teachers - -[Reference](https://nure-dev.pp.ua/#%D0%B7%D0%B0%D0%BF%D0%B8%D1%82-%D0%BD%D0%B0-%D0%B2%D0%B8%D0%BA%D0%BB%D0%B0%D0%B4%D0%B0%D1%87%D1%96%D0%B2) - -**Example:** - -```js -import { Nurekit } from "@nurejs/api" - -const nurekit = new Nurekit() - -const teachers = await nurekit.teachers.findMany() -``` - -**Output:** - -```ts -{ - id: number; - fullName: string; - shortName: string; -}[] -``` - -### Get teacher - -[Reference](https://nure-dev.pp.ua/#%D0%B7%D0%B0%D0%BF%D0%B8%D1%82-%D0%BD%D0%B0-%D0%B2%D0%B8%D0%BA%D0%BB%D0%B0%D0%B4%D0%B0%D1%87%D1%96%D0%B2) - -**Example:** - -```js -import { Nurekit } from "@nurejs/api" - -const nurekit = new Nurekit() - -const teachers = await nurekit.teachers.findOne("Боцюра О. А.") -``` - -**Input:** - -```ts -shortName: string; -``` - -**Output:** - -```ts -{ - id: number; - fullName: string; - shortName: string; -} -``` - -### Get schedule - -[Reference](https://nure-dev.pp.ua/#%D0%B7%D0%B0%D0%BF%D0%B8%D1%82-%D0%BD%D0%B0-%D1%80%D0%BE%D0%B7%D0%BA%D0%BB%D0%B0%D0%B4) - -**Example:** - -```js -import { Nurekit } from "@nurejs/api" - -const nurekit = new Nurekit() - - -// For auditorium -const schedule = await nurekit.auditoriums.getSchedule({ - auditoriumName: "287", - startTime: "2023-09-11", - endTime: "2023-09-15", -}); - -// For teacher -const schedule = await nurekit.teachers.getSchedule({ - teacherName: "Боцюра О. А.", - startTime: "2023-09-11", - endTime: "2023-09-15", -}); - -// For group -const schedule = await nurekit.groups.getSchedule({ - groupName: "пзпі-23-5", - startTime: "2023-09-11", - endTime: "2023-09-15", -}); -``` - -**Input:** - -```ts -// For auditorium - -{ - auditoriumName: string, - startTime: string, - endTime: string, -} - -// For teacher - -{ - teacherName: string, - startTime: string, - endTime: string, -} - -// For group - -{ - groupName: string, - startTime: string, - endTime: string, -} -``` - -**Output:** - -```ts -{ - id: number; - startTime: number; - endTime: number; - auditorium: string; - numberPair: number; - type: string; - updatedAt: Date; - groups: { - id: number; - name: string; - }[]; - teachers: { - id: number; - fullName: string; - shortName: string; - }[]; - subject: { - id: number; - brief: string; - title: string; - }; -}[] -``` +You can read documentation [here](https://onelil05.github.io/nurekit/) ## Stay in touch