Skip to content

Commit 8826fc5

Browse files
committed
merge from fix api helpers
2 parents 16856e6 + e37decf commit 8826fc5

18 files changed

+872
-135
lines changed

CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
## [1.27.6](https://github.com/ocadotechnology/codeforlife-package-javascript/compare/v1.27.5...v1.27.6) (2024-05-31)
2+
3+
4+
### Bug Fixes
5+
6+
* import ([9ba872b](https://github.com/ocadotechnology/codeforlife-package-javascript/commit/9ba872bc948f23059bc504c95e01b31c47cdb734))
7+
* linting errors ([23fbb17](https://github.com/ocadotechnology/codeforlife-package-javascript/commit/23fbb1724d3d99fd700c2fdc9dfad758e058fadf))
8+
* rtk helpers ([#40](https://github.com/ocadotechnology/codeforlife-package-javascript/issues/40)) ([3b7c90a](https://github.com/ocadotechnology/codeforlife-package-javascript/commit/3b7c90a73eb68399160a58e5995c588da95cc5d0))
9+
110
## [1.27.5](https://github.com/ocadotechnology/codeforlife-package-javascript/compare/v1.27.4...v1.27.5) (2023-10-24)
211

312

lib/cjs/api/models.d.ts

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { COUNTRY_ISO_CODES, UK_COUNTIES } from '../helpers/general';
2+
import type { Model } from '../helpers/rtkQuery';
3+
export type User = Model<number, {
4+
password: string;
5+
last_login?: Date;
6+
first_name: string;
7+
last_name?: string;
8+
email?: string;
9+
is_staff: boolean;
10+
is_active: boolean;
11+
date_joined: Date;
12+
requesting_to_join_class?: string;
13+
teacher?: Teacher;
14+
student?: Student;
15+
}>;
16+
export type Teacher = Model<number, {
17+
user: number;
18+
school?: number;
19+
is_admin: boolean;
20+
}>;
21+
export type Student = Model<number, {
22+
user: number;
23+
school: number;
24+
klass: string;
25+
}>;
26+
export type School = Model<number, {
27+
name: string;
28+
country?: (typeof COUNTRY_ISO_CODES)[number];
29+
uk_county?: (typeof UK_COUNTIES)[number];
30+
}>;
31+
export type Class = Model<string, {
32+
name: string;
33+
teacher: number;
34+
school: number;
35+
read_classmates_data: boolean;
36+
receive_requests_until?: Date;
37+
}>;
38+
export type AuthFactor = Model<number, {
39+
user: number;
40+
type: 'otp';
41+
}>;

lib/cjs/api/models.js

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });

lib/cjs/api/urls.d.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
declare const urls: Record<string, {
2+
list: string;
3+
detail: string;
4+
}>;
5+
export default urls;

lib/cjs/api/urls.js

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
var urls = {
4+
user: {
5+
list: 'users/',
6+
detail: 'users/<id>/'
7+
},
8+
teacher: {
9+
list: 'users/teachers/',
10+
detail: 'users/teachers/<id>/'
11+
},
12+
student: {
13+
list: 'users/students/',
14+
detail: 'users/students/<id>/'
15+
},
16+
school: {
17+
list: 'schools/',
18+
detail: 'schools/<id>/'
19+
},
20+
class: {
21+
list: 'classes/',
22+
detail: 'classes/<id>/'
23+
},
24+
otpBypassToken: {
25+
list: 'otp-bypass-tokens/',
26+
detail: 'otp-bypass-tokens/<id>/'
27+
},
28+
authFactor: {
29+
list: 'auth-factors/',
30+
detail: 'auth-factors/<id>/'
31+
}
32+
};
33+
exports.default = urls;

lib/esm/api/models.d.ts

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { COUNTRY_ISO_CODES, UK_COUNTIES } from '../helpers/general';
2+
import type { Model } from '../helpers/rtkQuery';
3+
export type User = Model<number, {
4+
password: string;
5+
last_login?: Date;
6+
first_name: string;
7+
last_name?: string;
8+
email?: string;
9+
is_staff: boolean;
10+
is_active: boolean;
11+
date_joined: Date;
12+
requesting_to_join_class?: string;
13+
teacher?: Teacher;
14+
student?: Student;
15+
}>;
16+
export type Teacher = Model<number, {
17+
user: number;
18+
school?: number;
19+
is_admin: boolean;
20+
}>;
21+
export type Student = Model<number, {
22+
user: number;
23+
school: number;
24+
klass: string;
25+
}>;
26+
export type School = Model<number, {
27+
name: string;
28+
country?: (typeof COUNTRY_ISO_CODES)[number];
29+
uk_county?: (typeof UK_COUNTIES)[number];
30+
}>;
31+
export type Class = Model<string, {
32+
name: string;
33+
teacher: number;
34+
school: number;
35+
read_classmates_data: boolean;
36+
receive_requests_until?: Date;
37+
}>;
38+
export type AuthFactor = Model<number, {
39+
user: number;
40+
type: 'otp';
41+
}>;

lib/esm/api/models.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {};

lib/esm/api/urls.d.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
declare const urls: Record<string, {
2+
list: string;
3+
detail: string;
4+
}>;
5+
export default urls;

lib/esm/api/urls.js

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
var urls = {
2+
user: {
3+
list: 'users/',
4+
detail: 'users/<id>/'
5+
},
6+
teacher: {
7+
list: 'users/teachers/',
8+
detail: 'users/teachers/<id>/'
9+
},
10+
student: {
11+
list: 'users/students/',
12+
detail: 'users/students/<id>/'
13+
},
14+
school: {
15+
list: 'schools/',
16+
detail: 'schools/<id>/'
17+
},
18+
class: {
19+
list: 'classes/',
20+
detail: 'classes/<id>/'
21+
},
22+
otpBypassToken: {
23+
list: 'otp-bypass-tokens/',
24+
detail: 'otp-bypass-tokens/<id>/'
25+
},
26+
authFactor: {
27+
list: 'auth-factors/',
28+
detail: 'auth-factors/<id>/'
29+
}
30+
};
31+
export default urls;

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "codeforlife",
3-
"version": "1.27.5",
3+
"version": "1.27.6",
44
"private": true,
55
"description": "Common frontend code",
66
"main": "./lib/cjs/index.js",

src/api/baseQuery.ts

+1
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ export function parseResponseBody(data: unknown): void {
112112
snakeCaseToCamelCase(data)
113113
}
114114

115+
// TODO: https://redux-toolkit.js.org/rtk-query/usage/customizing-queries#implementing-a-custom-basequery
115116
const baseQuery: FetchBaseQuery = async (args, api, extraOptions) => {
116117
await injectCsrfToken(fetch, args, api)
117118

src/api/endpoints.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ export default function endpoints<ReducerPath extends string>(
2323
const _build = build as EndpointBuilder<FetchBaseQuery, TagTypes, ReducerPath>
2424

2525
return {
26+
// TODO: https://redux-toolkit.js.org/rtk-query/usage/customizing-queries#implementing-a-queryfn
2627
logout: _build.mutation<LogoutResult, LogoutQuery>({
2728
query: () => ({
28-
url: "session/logout/",
29-
method: "GET",
30-
}),
31-
invalidatesTags: ["private"],
32-
}),
33-
}
29+
url: 'session/logout/',
30+
method: 'GET'
31+
})
32+
})
33+
};
3434
}

src/api/index.ts

+25-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,26 @@
1-
import baseQuery from "./baseQuery"
2-
import endpoints from "./endpoints"
3-
import tagTypes from "./tagTypes"
1+
import baseQuery from './baseQuery'
2+
import endpoints from './endpoints'
3+
import type {
4+
AuthFactor,
5+
Class,
6+
School,
7+
Student,
8+
Teacher,
9+
User
10+
} from './models'
11+
import tagTypes from './tagTypes'
12+
import urls from './urls'
13+
14+
export {
15+
baseQuery,
16+
endpoints,
17+
tagTypes,
18+
urls,
19+
type AuthFactor,
20+
type Class,
21+
type School,
22+
type Student,
23+
type Teacher,
24+
type User
25+
}
426

5-
export { baseQuery, endpoints, tagTypes }

src/api/models.ts

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import { COUNTRY_ISO_CODES, UK_COUNTIES } from '../helpers/general';
2+
import type { Model } from '../helpers/rtkQuery';
3+
4+
export type User = Model<
5+
number,
6+
{
7+
password: string;
8+
last_login?: Date;
9+
first_name: string;
10+
last_name?: string;
11+
email?: string;
12+
is_staff: boolean;
13+
is_active: boolean;
14+
date_joined: Date;
15+
requesting_to_join_class?: string;
16+
teacher?: Teacher;
17+
student?: Student;
18+
}
19+
>;
20+
21+
export type Teacher = Model<
22+
number,
23+
{
24+
user: number;
25+
school?: number;
26+
is_admin: boolean;
27+
}
28+
>;
29+
30+
export type Student = Model<
31+
number,
32+
{
33+
user: number;
34+
school: number;
35+
klass: string;
36+
}
37+
>;
38+
39+
export type School = Model<
40+
number,
41+
{
42+
name: string;
43+
country?: (typeof COUNTRY_ISO_CODES)[number];
44+
uk_county?: (typeof UK_COUNTIES)[number];
45+
}
46+
>;
47+
48+
export type Class = Model<
49+
string,
50+
{
51+
name: string;
52+
teacher: number;
53+
school: number;
54+
read_classmates_data: boolean;
55+
receive_requests_until?: Date;
56+
}
57+
>;
58+
59+
export type AuthFactor = Model<
60+
number,
61+
{
62+
user: number;
63+
type: 'otp';
64+
}
65+
>;

src/api/tagTypes.ts

+6-10
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
const tagTypes = [
2-
// A special tag used to mark data as private.
3-
// Private data will be invalidated on logout.
4-
"private",
5-
62
// These are the tags for the common models used throughout our system.
73
// https://github.com/ocadotechnology/codeforlife-package-python/tree/main/codeforlife/user/models
8-
"user",
9-
"school",
10-
"class",
11-
"teacher",
12-
"student",
13-
] as const
4+
// NOTE: Don't use the "Teacher" and "Student" tags. Use "User" instead.
5+
'User',
6+
'School',
7+
'Class',
8+
'AuthFactor'
9+
] as const;
1410

1511
export default tagTypes
1612
export type TagTypes = (typeof tagTypes)[number]

src/api/urls.ts

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
const urls: Record<
2+
string,
3+
{
4+
list: string;
5+
detail: string;
6+
}
7+
> = {
8+
user: {
9+
list: 'users/',
10+
detail: 'users/<id>/'
11+
},
12+
teacher: {
13+
list: 'users/teachers/',
14+
detail: 'users/teachers/<id>/'
15+
},
16+
student: {
17+
list: 'users/students/',
18+
detail: 'users/students/<id>/'
19+
},
20+
school: {
21+
list: 'schools/',
22+
detail: 'schools/<id>/'
23+
},
24+
class: {
25+
list: 'classes/',
26+
detail: 'classes/<id>/'
27+
},
28+
otpBypassToken: {
29+
list: 'otp-bypass-tokens/',
30+
detail: 'otp-bypass-tokens/<id>/'
31+
},
32+
authFactor: {
33+
list: 'auth-factors/',
34+
detail: 'auth-factors/<id>/'
35+
}
36+
};
37+
38+
export default urls;

0 commit comments

Comments
 (0)