Skip to content

Commit

Permalink
refactored types
Browse files Browse the repository at this point in the history
  • Loading branch information
Przemek committed Jan 14, 2025
1 parent 8acd517 commit 027d503
Show file tree
Hide file tree
Showing 23 changed files with 1,016 additions and 1,018 deletions.
995 changes: 0 additions & 995 deletions src/types/api.ts

This file was deleted.

61 changes: 61 additions & 0 deletions src/types/auth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { DefaultResponse, DefaultResponseError } from "./core";

export type LoginRequest = {
email: string;
password: string;
remember_me?: 1 | 0;
};

export type LoginResponse = DefaultResponse<{
token: string;
expires_at: string;
}>;

export type RegisterRequest = {
email: string;
password: string;
password_confirmation: string;
first_name: string;
last_name: string;
return_url: string;
} & Record<string, string | number | boolean>;

export type RegisterResponse =
| {
success: true;
token: string;
}
| DefaultResponseError;

export type ForgotRequest = {
email: string;
return_url: string;
};

export type AuthResponse =
| {
message: string;
success: boolean;
}
| DefaultResponseError;

export type ResetPasswordRequest = {
token: string;
password: string;
email: string;
};

export type ChangePasswordRequest = {
current_password: string;
new_password: string;
new_confirm_password: string;
};

export type UpdateUserEmail = {
email?: string;
};

export interface CompleteSocialAuth {
email: string;
return_url: string;
}
56 changes: 56 additions & 0 deletions src/types/bookmark.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { DefaultMetaResponse, Nullable, PaginationParams } from "./core";
import { BookmarkableType, TopicType } from "./enums";
import { User } from "./user";

export type BookmarkNoteBase = {
id: number;
value: string | null;
created_at: Date | string;
updated_at: Date | string;
bookmarkable_id: number;
user_id: number;
user: Nullable<User>;
};

export type BookmarkCourse = BookmarkNoteBase & {
bookmarkable_type: BookmarkableType.Course;
// TODO: after backend support this should be typed well
bookmarkable: null;
};

export type BookmarkLesson = BookmarkNoteBase & {
bookmarkable_type: BookmarkableType.Lesson;
// TODO: after backend support this should be typed well
bookmarkable: null;
};

export type BookmarkTopic = BookmarkNoteBase & {
bookmarkable_type: BookmarkableType.Topic;
bookmarkable: {
id: number;
title: string;
type: TopicType;
lesson_id: number;
course_id: number;
course_title: string;
};
};

export type BookmarkNoteParams =
EscolaLms.Bookmarks.Http.Requests.ListBookmarkRequest &
PaginationParams & {
order_by?: "created_at" | "id" | "value";
order?: "ASC" | "DESC";
has_value?: boolean | 1 | 0;
bookmarkable_id?: number;
bookmarkable_ids?: number[];
bookmarkable_type?: BookmarkableType;
};

export type CreateBookmarkNote = {
value: Nullable<string>;
bookmarkable_id: number;
bookmarkable_type: BookmarkableType;
};
export type BookmarkNote = BookmarkCourse | BookmarkLesson | BookmarkTopic;
export type BookmarkNoteList = DefaultMetaResponse<BookmarkNote>;
14 changes: 13 additions & 1 deletion src/types/cart-types.ts → src/types/cart.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { User } from "./user-types";
import { DefaultMetaResponse, DefaultResponse } from "./core";
import { User } from "./user";

export type Product = Omit<EscolaLms.Cart.Models.Product, "productables"> & {
available_quantity: number;
Expand Down Expand Up @@ -61,3 +62,14 @@ export type CartItem = EscolaLms.Cart.Models.CartItem & {
product_id?: number;
total_with_tax?: number;
};

export type AddProductResponse = DefaultResponse<{
buyable: boolean;
difference: number;
limit: number;
operation: "increment" | "decrement" | "unchanged";
quantity_in_cart: number;
quantity_owned: number;
}>;

export type ProductList = DefaultMetaResponse<Product>;
70 changes: 70 additions & 0 deletions src/types/competency.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { DefaultMetaResponse, Nullable, PaginationParams } from "./core";
import { CompetencyChallengeType } from "./enums";
import { Author } from "./user";

export type Scale = {
parent_category_id: number;
category_id: number;
scale_min: number;
};

export type ResultValue = {
category_id: number;
scale_category_id: number;
parent_category_id: number;
score: number;
max_score: number;
matched_course: number[];
};

export type CompetencyTestResults = {
attempt_id: number;
created_at: string;
id: number;
scale: Scale[][];
value: ResultValue[];
};

export type CompetencyChallengeCategory = {
id: number;
name: string;
parent_id?: number;
};

export type BaseCompetencyChallenge = {
id: number;
name: string;
description: string;
summary: string;
image_path?: Nullable<string>;
is_active: boolean;
is_highlighted: boolean;
quiz_id?: Nullable<number>;
created_at: Date | string;
categories?: number[];
authors?: Author[];
results: CompetencyTestResults[];
results_count: number;
};

export type SimpleCompetencyChallenge = BaseCompetencyChallenge & {
type: CompetencyChallengeType.Simple;
category: CompetencyChallengeCategory;
};

export type ComplexCompetencyChallenge = BaseCompetencyChallenge & {
type: CompetencyChallengeType.Complex;
};

export type CompetencyChallenge =
| SimpleCompetencyChallenge
| ComplexCompetencyChallenge;

export type ChallengesList = DefaultMetaResponse<CompetencyChallenge>;

export type ChallengesParams = PaginationParams & {
order_by?: "id" | "name" | "created_at";
type?: "simple" | "complex";
order?: "ASC" | "DESC";
name?: string;
};
6 changes: 3 additions & 3 deletions src/types/consultation-types.ts → src/types/consultation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import {
DefaultResponseError,
PageParams,
PaginationParams,
} from "./core-types";
import { User, UserItem } from "./user-types";
} from "./core";
import { User, UserItem } from "./user";
import { API } from "..";
import { Product } from "./cart-types";
import { Product } from "./cart";

export type Consultation = EscolaLms.Consultations.Models.Consultation & {
product?: Product;
Expand Down
85 changes: 85 additions & 0 deletions src/types/core-types.ts → src/types/core.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,49 @@
import { IEvent } from "./enums";
import { UserItem } from "./user";

export type Nullable<T> = T | null | undefined;

export type AppCurrency = {
default: string;
enum: string[];
};

export type AppSettings = any & {
currencies?: AppCurrency;
consents?: {
[key: string]: string;
};
faq?: {
[key: string]: string;
};
homepage?: Record<string, Record<string, string>>;
register?: {
[key: string]: string;
};
env?: string;
stripe?: {
publishable_key: string;
};
global?: {
[key: string]: string;
};
};

export type AppConfig = Record<string, Record<string, string[] | string>>;

export type IStatement = {
actor: unknown;
context: {
contextActivities: {
category: IStatementCategory[];
parent?: IStatementCategory[];
};
};
object: unknown;
result?: IResult;
verb: { id: IEvent };
};

export type IStatementCategory = {
id: string;
objectType: "string";
Expand Down Expand Up @@ -141,3 +185,44 @@ export type Tag = {
};

export type CategoryListItem = Category;

export type Pdf = {
title: string;
};

export type FieldsParams = {
class_type: string;
};

export type Metadata = Omit<EscolaLms.ModelFields.Models.Metadata, "rules"> & {
rules: string | string[] | null;
};

export type Page = {
id: number;
slug: string;
title: string;
author_id: number;
author: UserItem;
content: string;
};

export type Template = {
id: number;
name: string;
event: string;
channel: string;
created_at: Date;
updated_at: Date;
title: string | null;
mail_theme: null;
mail_markdown: null;
is_default: boolean;
assignable_type: null;
assignable_id: null;
default: boolean;
};

export type PageList = DefaultMetaResponse<Page>;
export type CategoryList = DataResponseSuccess<Category[]>;
export type PageListItem = Page;
10 changes: 5 additions & 5 deletions src/types/course-types.ts → src/types/course.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import {
PaginatedListParams,
PaginationParams,
Tag,
} from "./core-types";
import { UserItem } from "./user-types";
} from "./core";
import { UserItem } from "./user";
import { CourseProgressItemElementStatus } from "./enums";

import { Topic } from "./topic-types";
import { Product } from "./cart-types";
import { SCORM, SCORM_SCO } from "./scorm-types";
import { Topic } from "./topic";
import { Product } from "./cart";
import { SCORM, SCORM_SCO } from "./scorm";

export type Course = {
id: number;
Expand Down
44 changes: 44 additions & 0 deletions src/types/dictionary.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { Category, PaginationParams } from "./core";

export type DictionariesParams = {
word?: string;
// Example: url?category_ids[]=1&category_ids[]=2category_ids[]=3
"category_ids[]"?: number[];
word_start?: string;
abort_prev?: boolean;
};

export type DictionariesWordsParams = DictionariesParams & PaginationParams;

export type DictionariesWordsCategory = Pick<
Category,
"name" | "name_with_breadcrumbs" | "id"
>;

export type DictionaryWordData = {
id?: number;
title?: string;
description?: string;
video_url?: string;
};

export type DictionariesWords = {
id: number;
word: string;
dictionary_id: number;
created_at: string;
updated_at: string;
categories: DictionariesWordsCategory[];
description?: string;
data?: {
descriptions?: DictionaryWordData[];
};
};

export type DictionariesAccess = {
dictionary_id: number;
name: string;
slug: string;
end_date: string;
is_active: boolean;
};
Loading

0 comments on commit 027d503

Please sign in to comment.