Skip to content

Commit

Permalink
get read only endpoints of user objects from js package
Browse files Browse the repository at this point in the history
  • Loading branch information
SKairinos committed Jul 8, 2024
1 parent 5ae4951 commit 9c0154e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 107 deletions.
16 changes: 6 additions & 10 deletions src/api/authFactor.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
import { urls, type AuthFactor } from "codeforlife/api"
import {
getReadAuthFactorEndpoints,

Check failure on line 2 in src/api/authFactor.ts

View workflow job for this annotation

GitHub Actions / main / test / test-js-code

Module '"codeforlife/api"' has no exported member 'getReadAuthFactorEndpoints'.
urls,
type AuthFactor,
} from "codeforlife/api"
import {
buildUrl,
tagData,
type CreateArg,
type CreateResult,
type DestroyArg,
type DestroyResult,
type ListArg,
type ListResult,
} from "codeforlife/utils/api"

import api from "."

const authFactorApi = api.injectEndpoints({
endpoints: build => ({
...getReadAuthFactorEndpoints(build),
createAuthFactor: build.mutation<
CreateResult<AuthFactor>,
CreateArg<AuthFactor, "type">
Expand All @@ -31,13 +34,6 @@ const authFactorApi = api.injectEndpoints({
}),
invalidatesTags: tagData("AuthFactor"),
}),
listAuthFactors: build.query<ListResult<AuthFactor, "type">, ListArg>({
query: search => ({
url: buildUrl(urls.authFactor.list, { search }),
method: "GET",
}),
providesTags: tagData("AuthFactor"),
}),
}),
})

Expand Down
41 changes: 2 additions & 39 deletions src/api/klass.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import { urls, type Class } from "codeforlife/api"
import { getReadClassEndpoints, urls, type Class } from "codeforlife/api"

Check failure on line 1 in src/api/klass.ts

View workflow job for this annotation

GitHub Actions / main / test / test-js-code

Module '"codeforlife/api"' has no exported member 'getReadClassEndpoints'.
import {
buildUrl,
tagData,
type CreateArg,
type CreateResult,
type DestroyArg,
type DestroyResult,
type ListArg,
type ListResult,
type RetrieveArg,
type RetrieveResult,
type UpdateArg,
type UpdateResult,
} from "codeforlife/utils/api"
Expand All @@ -18,6 +14,7 @@ import api from "."

const classApi = api.injectEndpoints({
endpoints: build => ({
...getReadClassEndpoints(build),
createClass: build.mutation<
CreateResult<Class>,
CreateArg<
Expand Down Expand Up @@ -54,40 +51,6 @@ const classApi = api.injectEndpoints({
}),
invalidatesTags: tagData("Class"),
}),
retrieveClass: build.query<
RetrieveResult<
Class,
| "name"
| "read_classmates_data"
| "receive_requests_until"
| "school"
| "teacher"
>,
RetrieveArg<Class>
>({
query: id => ({
url: buildUrl(urls.class.detail, { url: { id } }),
method: "GET",
}),
providesTags: tagData("Class"),
}),
listClasses: build.query<
ListResult<
Class,
| "name"
| "read_classmates_data"
| "receive_requests_until"
| "school"
| "teacher"
>,
ListArg
>({
query: search => ({
url: buildUrl(urls.class.list, { search }),
method: "GET",
}),
providesTags: tagData("Class"),
}),
}),
})

Expand Down
15 changes: 2 additions & 13 deletions src/api/school.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { urls, type School } from "codeforlife/api"
import { getReadSchoolEndpoints, urls, type School } from "codeforlife/api"

Check failure on line 1 in src/api/school.ts

View workflow job for this annotation

GitHub Actions / main / test / test-js-code

Module '"codeforlife/api"' has no exported member 'getReadSchoolEndpoints'.
import {
buildUrl,
tagData,
type CreateArg,
type CreateResult,
type RetrieveArg,
type RetrieveResult,
type UpdateArg,
type UpdateResult,
} from "codeforlife/utils/api"
Expand All @@ -14,16 +12,7 @@ import api from "."

const schoolApi = api.injectEndpoints({
endpoints: build => ({
retrieveSchool: build.query<
RetrieveResult<School, "name" | "country" | "uk_county">,
RetrieveArg<School>
>({
query: id => ({
url: buildUrl(urls.school.detail, { url: { id } }),
method: "GET",
}),
providesTags: tagData("School"),
}),
...getReadSchoolEndpoints(build),
createSchool: build.mutation<
CreateResult<School>,
CreateArg<School, "name", "country" | "uk_county">
Expand Down
47 changes: 2 additions & 45 deletions src/api/user.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { urls, type User } from "codeforlife/api"
import { getReadUserEndpoints, urls, type User } from "codeforlife/api"

Check failure on line 1 in src/api/user.ts

View workflow job for this annotation

GitHub Actions / main / test / test-js-code

Module '"codeforlife/api"' has no exported member 'getReadUserEndpoints'.
import {
buildUrl,
tagData,
Expand All @@ -7,10 +7,6 @@ import {
type CreateResult,
type DestroyArg,
type DestroyResult,
type ListArg,
type ListResult,
type RetrieveArg,
type RetrieveResult,
type UpdateArg,
type UpdateResult,
} from "codeforlife/utils/api"
Expand All @@ -19,6 +15,7 @@ import api from "."

const userApi = api.injectEndpoints({
endpoints: build => ({
...getReadUserEndpoints(build),
handleJoinClassRequest: build.mutation<
UpdateResult<User>,
UpdateArg<User, never, "first_name", { accept: boolean }>
Expand Down Expand Up @@ -101,46 +98,6 @@ const userApi = api.injectEndpoints({
body,
}),
}),
retrieveUser: build.query<
RetrieveResult<
User,
| "first_name"
| "last_name"
| "email"
| "is_active"
| "date_joined"
| "requesting_to_join_class"
| "student"
| "teacher"
>,
RetrieveArg<User>
>({
query: id => ({
url: buildUrl(urls.user.detail, { url: { id } }),
method: "GET",
}),
providesTags: tagData("User"),
}),
listUsers: build.query<
ListResult<
User,
| "first_name"
| "last_name"
| "email"
| "is_active"
| "date_joined"
| "requesting_to_join_class"
| "student"
| "teacher"
>,
ListArg<{ students_in_class: string }>
>({
query: search => ({
url: buildUrl(urls.user.list, { search }),
method: "GET",
}),
providesTags: tagData("User"),
}),
}),
})

Expand Down

0 comments on commit 9c0154e

Please sign in to comment.