Summary: Adding validation for api /records endpoint, that checks if the json payload is valid. Modifying POST /records endpoint to allow creating blank or partial records. Test Plan: Updated tests Reviewers: alexmojaki Reviewed By: alexmojaki Differential Revision: https://phab.getgrist.com/D3061pull/115/head
parent
276adc5f51
commit
3e661db38c
@ -0,0 +1,34 @@
|
||||
/**
|
||||
* This module was automatically generated by `ts-interface-builder`
|
||||
*/
|
||||
import * as t from "ts-interface-checker";
|
||||
// tslint:disable:object-literal-key-quotes
|
||||
|
||||
export const GristObjCode = t.enumtype({
|
||||
"List": "L",
|
||||
"Dict": "O",
|
||||
"DateTime": "D",
|
||||
"Date": "d",
|
||||
"Skip": "S",
|
||||
"Censored": "C",
|
||||
"Reference": "R",
|
||||
"ReferenceList": "r",
|
||||
"Exception": "E",
|
||||
"Pending": "P",
|
||||
"Unmarshallable": "U",
|
||||
"Versions": "V",
|
||||
});
|
||||
|
||||
export const CellValue = t.union("number", "string", "boolean", "null", t.tuple("GristObjCode", t.rest(t.array("unknown"))));
|
||||
|
||||
export const RowRecord = t.iface([], {
|
||||
"id": "number",
|
||||
[t.indexKey]: "CellValue",
|
||||
});
|
||||
|
||||
const exportedTypeSuite: t.ITypeSuite = {
|
||||
GristObjCode,
|
||||
CellValue,
|
||||
RowRecord,
|
||||
};
|
||||
export default exportedTypeSuite;
|
@ -0,0 +1,34 @@
|
||||
/**
|
||||
* This module was automatically generated by `ts-interface-builder`
|
||||
*/
|
||||
import * as t from "ts-interface-checker";
|
||||
// tslint:disable:object-literal-key-quotes
|
||||
|
||||
export const NewRecord = t.iface([], {
|
||||
"fields": t.opt(t.iface([], {
|
||||
[t.indexKey]: "CellValue",
|
||||
})),
|
||||
});
|
||||
|
||||
export const Record = t.iface([], {
|
||||
"id": "number",
|
||||
"fields": t.iface([], {
|
||||
[t.indexKey]: "CellValue",
|
||||
}),
|
||||
});
|
||||
|
||||
export const RecordsPatch = t.iface([], {
|
||||
"records": t.tuple("Record", t.rest(t.array("Record"))),
|
||||
});
|
||||
|
||||
export const RecordsPost = t.iface([], {
|
||||
"records": t.tuple("NewRecord", t.rest(t.array("NewRecord"))),
|
||||
});
|
||||
|
||||
const exportedTypeSuite: t.ITypeSuite = {
|
||||
NewRecord,
|
||||
Record,
|
||||
RecordsPatch,
|
||||
RecordsPost,
|
||||
};
|
||||
export default exportedTypeSuite;
|
@ -0,0 +1,30 @@
|
||||
import { CellValue } from "app/plugin/GristData";
|
||||
|
||||
/**
|
||||
* JSON schema for api /record endpoint. Used in POST method for adding new records.
|
||||
*/
|
||||
export interface NewRecord {
|
||||
fields?: { [coldId: string]: CellValue }; // fields is optional, user can create blank records
|
||||
}
|
||||
|
||||
/**
|
||||
* JSON schema for api /record endpoint. Used in PATCH method for updating existing records.
|
||||
*/
|
||||
export interface Record {
|
||||
id: number;
|
||||
fields: { [coldId: string]: CellValue };
|
||||
}
|
||||
|
||||
/**
|
||||
* JSON schema for the body of api /record PATCH endpoint
|
||||
*/
|
||||
export interface RecordsPatch {
|
||||
records: [Record, ...Record[]]; // at least one record is required
|
||||
}
|
||||
|
||||
/**
|
||||
* JSON schema for the body of api /record POST endpoint
|
||||
*/
|
||||
export interface RecordsPost {
|
||||
records: [NewRecord, ...NewRecord[]]; // at least one record is required
|
||||
}
|
Loading…
Reference in new issue