Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions src/api/SubjectsApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ import { ApiPost } from '@/api/ApiTypes';
import { newDateField } from '@/model/field/DateField';
import { newTextField } from '@/model/field/TextField';
import { newHtmlField } from '@/model/field/HtmlField';

const endpoints = new Map< string, string >( [
[ SubjectType.BlogPost, '/blog-posts' ],
[ SubjectType.Page, '/pages' ],
] );
import { getSchema } from '@/model/Schema';

export class SubjectsApi {
constructor( private readonly client: ApiClient ) {}
Expand Down Expand Up @@ -47,11 +43,8 @@ export class SubjectsApi {
}

function getEndpoint( type: SubjectType ): string {
const endpoint = endpoints.get( type );
if ( ! endpoint ) {
throw Error( `unknown endpoint: ${ type }` );
}
return endpoint;
const schema = getSchema( type );
return `/${ schema.slug }s`;
}

function fromApiResponse( response: ApiPost ): Subject {
Expand Down
Loading