Skip to content

Commit

Permalink
Merge pull request #6 from OneLiL05/feature
Browse files Browse the repository at this point in the history
feat: 0.2.0 version release
  • Loading branch information
OneLiL05 authored Sep 5, 2023
2 parents 7ad4fce + c44c66f commit 129641d
Show file tree
Hide file tree
Showing 5 changed files with 186 additions and 30 deletions.
20 changes: 9 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ 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/CONTIRBUTING.md)
If you want to contribute to improving the project, firstly read [CONTIRBUTING.md](https://github.com/OneLiL05/nurekit/blob/main/CONTRIBUTING.md)

## Methods

Expand Down Expand Up @@ -55,7 +55,7 @@ import { Nurekit } from "@nurejs/api"

const nurekit = new Nurekit()

const auditories = await nurekit.auditoriums.findOne({ name: "285" })
const auditories = await nurekit.auditoriums.findOne("285")
```

**Input:**
Expand Down Expand Up @@ -107,7 +107,7 @@ import { Nurekit } from "@nurejs/api"

const nurekit = new Nurekit()

const groups = await nurekit.groups.findOne({ name: "пзпі-23-5" })
const groups = await nurekit.groups.findOne("пзпі-23-5")
```

**Input:**
Expand Down Expand Up @@ -162,15 +162,13 @@ import { Nurekit } from "@nurejs/api"

const nurekit = new Nurekit()

const teachers = await nurekit.teachers.findOne({ shortName: "Боцюра О. А." })
const teachers = await nurekit.teachers.findOne("Боцюра О. А.")
```

**Input:**

```ts
{
shortName: string;
}
shortName: string;
```

**Output:**
Expand All @@ -196,8 +194,8 @@ const nurekit = new Nurekit()

const schedule = await nurekit.groups.getSchedule({
groupName: "пзпі-23-5",
startTime: 1693170000,
endTime: 1694811599,
startTime: "2023-09-11",
endTime: "2023-09-15",
});
```

Expand All @@ -206,8 +204,8 @@ const schedule = await nurekit.groups.getSchedule({
```ts
{
groupName: string,
startTime: number,
endTime: number,
startTime: string,
endTime: string,
}
```

Expand Down
5 changes: 5 additions & 0 deletions src/helpers/date.helper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export function toTimestamp(stringDate: string) {
const parsedDate = Date.parse(stringDate);

return parsedDate / 1000;
}
44 changes: 39 additions & 5 deletions src/modules/auditoriums.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,53 @@ import { handleAxiosError } from "../helpers/axios.helper.js";
import { axiosClient } from "../libs/axios.js";
import { IAuditorium } from "../types/index.js";

interface FindOneParams {
name: string;
}

export class AuditoriumsModule {
/**
* Method returns array of objects with such fields:
* ```typescript
* {
* id: number;
* name: string;
* }
* ```
*
* Example usage:
* ```typescript
const auditoriums = await nurekit.auditoriums.findMany()
* ```
*
* @see [Docs](https://github.com/OneLiL05/nurekit#get-auditoriums)
*
* @publicApi
*/
public async findMany(): Promise<IAuditorium[]> {
return axiosClient
.get<IAuditorium[]>("/api/auditories")
.then((res) => res.data)
.catch(handleAxiosError);
}

public async findOne({ name }: FindOneParams): Promise<IAuditorium> {
/**
* Method returns object with such fields:
* ```typescript
* {
* id: number;
* name: string;
* }
* ```
*
* Example usage:
* ```typescript
const auditorium = await nurekit.auditoriums.findOne({ name: "285" })
* ```
*
* @param name name of auditorium you want to get info about
*
* @see [Docs](https://github.com/OneLiL05/nurekit#get-auditorium)
*
* @publicApi
*/
public async findOne(name: string): Promise<IAuditorium> {
const auditoriums = await this.findMany();

const auditorium = auditoriums.find(
Expand Down
101 changes: 92 additions & 9 deletions src/modules/groups.module.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,62 @@
import { handleAxiosError } from "../helpers/axios.helper.js";
import { toTimestamp } from "../helpers/date.helper.js";
import { transformSchedule } from "../helpers/schedule.helper.js";
import { IGroup, IRawSchedule, ISchedule } from "../index.js";
import { axiosClient } from "../libs/axios.js";

interface FindOneParams {
name: string;
}

interface GetScheduleParams {
groupName: string;
startTime: number;
endTime: number;
startTime: string;
endTime: string;
}

export class GroupsModule {
/**
* Method returns array of objects with such fields:
* ```typescript
* {
* id: number;
* name: string;
* }
* ```
*
* Example usage:
* ```typescript
const group = await nurekit.groups.findMany()
* ```
*
* @see [Docs](https://github.com/OneLiL05/nurekit#get-groups)
*
* @publicApi
*/
public async findMany(): Promise<IGroup[]> {
return axiosClient
.get<IGroup[]>("/api/groups")
.then((res) => res.data)
.catch(handleAxiosError);
}

public async findOne({ name }: FindOneParams): Promise<IGroup> {
/**
* Method returns object with such fields:
* ```typescript
* {
* id: number;
* name: string;
* }
* ```
*
* Example usage:
* ```typescript
const group = await nurekit.groups.findOne("пзпі-23-5")
* ```
*
* @param name name of group you want to get info about
*
* @see [Docs](https://github.com/OneLiL05/nurekit#get-a-group)
*
* @publicApi
*/
public async findOne(name: string): Promise<IGroup> {
const groups = await this.findMany();

const group = groups.find((group) => group.name === name.toUpperCase());
Expand All @@ -33,16 +68,64 @@ export class GroupsModule {
return group;
}

/**
* Method returns schedule:
* ```typescript
*{
* 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;
* };
*}[]
* ```
*
* Example usage:
* ```typescript
const schedule = await nurekit.groups.getSchedule({
groupName: "пзпі-23-5",
startTime: "2023-09-11",
endTime: "2023-09-15",
});
* ```
*
* @param groupName name of group you want to get schedule for
* @param startTime
* @param endTime
*
* @see [Docs](https://github.com/OneLiL05/nurekit#get-schedule)
*
* @publicApi
*/
public async getSchedule({
groupName,
startTime,
endTime,
}: GetScheduleParams): Promise<ISchedule[]> {
const { id: groupId } = await this.findOne({ name: groupName });
const { id: groupId } = await this.findOne(groupName);

const startTimestamp = toTimestamp(startTime);
const endTimestamp = toTimestamp(endTime);

const rawSchedule = await axiosClient
.get<IRawSchedule[]>(
`/api/schedule?type=group&id=${groupId}&start_time=${startTime}&end_time=${endTime}`,
`/api/schedule?type=group&id=${groupId}&start_time=${startTimestamp}&end_time=${endTimestamp}`,
)
.then((res) => res.data)
.catch(handleAxiosError);
Expand Down
46 changes: 41 additions & 5 deletions src/modules/teachers.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,26 @@ import { transformTeachers } from "../helpers/teachers.helper.js";
import { axiosClient } from "../libs/axios.js";
import { IRawTeacher, ITeacher } from "../types/index.js";

interface FindOneParams {
shortName: string;
}

export class TeachersModule {
/**
* Method returns array of objects with such fields:
* ```typescript
* {
* id: number;
* fullName: string;
* shortName: string;
* }
* ```
*
* Example usage:
* ```typescript
const teachers = await nurekit.teachers.findMany()
* ```
*
* @see [Docs](https://github.com/OneLiL05/nurekit#get-teachers)
*
* @publicApi
*/
public async findMany(): Promise<ITeacher[]> {
const rawTeachers = await axiosClient
.get<IRawTeacher[]>("/api/teachers")
Expand All @@ -19,7 +34,28 @@ export class TeachersModule {
return result;
}

public async findOne({ shortName }: FindOneParams): Promise<ITeacher> {
/**
* Method returns object with such fields:
* ```typescript
* {
* id: number;
* fullName: string;
* shortName: string;
* }
* ```
*
* Example usage:
* ```typescript
const teacher = await nurekit.teachers.findOne("Боцюра О. А.")
* ```
*
* @param shortName short name of teacher you want to get info about
*
* @see [Docs](https://github.com/OneLiL05/nurekit#get-teachers )
*
* @publicApi
*/
public async findOne(shortName: string): Promise<ITeacher> {
const teachers = await this.findMany();

const teacher = teachers.find((teacher) => {
Expand Down

0 comments on commit 129641d

Please sign in to comment.