Skip to content

Instantly share code, notes, and snippets.

@JanPlazovnik
Created June 5, 2022 09:44

Revisions

  1. JanPlazovnik created this gist Jun 5, 2022.
    30 changes: 30 additions & 0 deletions jsend.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    export interface ApiResponse {
    status: 'success' | 'fail' | 'error';
    data?: any;
    message?: any;
    }

    export class jsend {
    // https://github.com/omniti-labs/jsend
    public static success(data: any): ApiResponse {
    return {
    status: 'success',
    data,
    };
    }

    public static fail(data: any): ApiResponse {
    return {
    status: 'fail',
    data,
    };
    }

    public static error(message: string | null, data?: any): ApiResponse {
    return {
    status: 'error',
    message,
    data,
    };
    }
    }