converted to Partials

This commit is contained in:
j-weissen 2022-10-04 11:24:20 +02:00
parent b49a4c3ddf
commit 057bcdcf02
2 changed files with 7 additions and 7 deletions

View file

@ -1,10 +1,10 @@
import type {Note} from "../types";
import type {Note} from "./types";
export interface NoteRepository {
getNotes(): Promise<Note[]>;
getNote(id: number): Promise<Note>;
getCurrentNote(): Promise<Note | void>;
updateNote(id: number, note: Note): Promise<Note>;
updateNote(id: number, note: Partial<Note>): Promise<Note>;
deleteNote(id: number): void;
createNote(note: Note): Promise<Note>;
createNote(note: Partial<Note> & Pick<Note, 'title'>): Promise<Note>;
}

View file

@ -1,4 +1,4 @@
import type {Note} from "../types";
import type {Note} from "./types";
import {parseCookies} from "nookies";
import type {NoteRepository} from "./NoteRepository";
@ -35,12 +35,12 @@ export class StrapiNoteRepository implements NoteRepository {
return await this.getNote(this.currentNoteId);
}
public async updateNote(id: number, note: Note): Promise<Note> {
public async updateNote(id: number, note: Partial<Note>): Promise<Note> {
const response = await StrapiNoteRepository.fetchStrapi("/" + id, 'PUT', note);
return await response.json();
}
public async createNote(note: Note): Promise<Note> {
public async createNote(note: Partial<Note> & Pick<Note, 'title'>): Promise<Note> {
const response = await StrapiNoteRepository.fetchStrapi("/", 'POST', note);
return await response.json();
}
@ -49,7 +49,7 @@ export class StrapiNoteRepository implements NoteRepository {
await StrapiNoteRepository.fetchStrapi("/" + id, 'DELETE');
}
private static async fetchStrapi(path: string, method: HttpMethod, body: Note | null = null): Promise<Response> {
private static async fetchStrapi(path: string, method: HttpMethod, body: Partial<Note> | null = null): Promise<Response> {
let requestInit: RequestInit = {
method: method,
headers: {