Skip to content
This repository has been archived by the owner on Oct 6, 2023. It is now read-only.

Commit

Permalink
♻️ Allowed nullable state
Browse files Browse the repository at this point in the history
  • Loading branch information
Schotsl committed Nov 17, 2022
1 parent 9173c3a commit 9e3532b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ export function populateInstance(

// TODO: Make sure we convert MySQL number formatted as strings to numbers so the REST API can be strict

if (type !== ColumnType.UnknownColumn) {
if (type !== ColumnType.UnknownColumn && title in body) {
instance[title].setValue(value);
} else {
instance[title] = value;
Expand Down
36 changes: 18 additions & 18 deletions other/Columns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { restoreUUID } from "../helper.ts";

export class StringColumn {
public required: boolean;
public value?: string;
public value?: string | null;
public title: string;

constructor(title: string, required = true, value?: string) {
Expand All @@ -41,7 +41,7 @@ export class StringColumn {
}

setValue(value?: string) {
const required = this.required && typeof this.value === "undefined";
const required = this.required && (typeof this.value === "undefined" || this.value == null);
const result = validateString(value, this.title, required);

if (result) {
Expand All @@ -56,7 +56,7 @@ export class StringColumn {

export class UrlColumn extends StringColumn {
setValue(value?: string) {
const required = this.required && typeof this.value === "undefined";
const required = this.required && (typeof this.value === "undefined" || this.value == null);
const result = validateUrl(value, this.title, required);

if (result) {
Expand All @@ -67,7 +67,7 @@ export class UrlColumn extends StringColumn {

export class EmailColumn extends StringColumn {
setValue(value?: string) {
const required = this.required && typeof this.value === "undefined";
const required = this.required && (typeof this.value === "undefined" || this.value == null);
const result = validateEmail(value, this.title, required);

if (result) {
Expand All @@ -78,7 +78,7 @@ export class EmailColumn extends StringColumn {

export class TimeColumn extends StringColumn {
setValue(value?: string) {
const required = this.required && typeof this.value === "undefined";
const required = this.required && (typeof this.value === "undefined" || this.value == null);
const result = validateTime(value, this.title, required);

if (result) {
Expand All @@ -102,7 +102,7 @@ export class UUIDColumn extends StringColumn {
value = restoreUUID(value);
}

const required = this.required && typeof this.value === "undefined";
const required = this.required && (typeof this.value === "undefined" || this.value == null);
const result = validateUUID(value, this.title, required);

if (result) {
Expand All @@ -114,7 +114,7 @@ export class UUIDColumn extends StringColumn {

export class VarcharColumn extends StringColumn {
setValue(value?: string) {
const required = this.required && typeof this.value === "undefined";
const required = this.required && (typeof this.value === "undefined" || this.value == null);
const result = validateVarchar(value, this.title, required);

if (result) {
Expand All @@ -125,7 +125,7 @@ export class VarcharColumn extends StringColumn {

export class LargeColumn extends StringColumn {
setValue(value?: string) {
const required = this.required && typeof this.value === "undefined";
const required = this.required && (typeof this.value === "undefined" || this.value == null);
const result = validateLarge(value, this.title, required);

if (result) {
Expand All @@ -136,7 +136,7 @@ export class LargeColumn extends StringColumn {

export class IPv64Column extends StringColumn {
setValue(value?: string) {
const required = this.required && typeof this.value === "undefined";
const required = this.required && (typeof this.value === "undefined" || this.value == null);
const result = validateIPv64(value, this.title, required);

if (result) {
Expand All @@ -162,7 +162,7 @@ export class NumberColumn {
}

setValue(value?: number) {
const required = this.required && typeof this.value === "undefined";
const required = this.required && (typeof this.value === "undefined" || this.value == null);
const result = validateNumber(value, this.title, required);

if (result) {
Expand All @@ -177,7 +177,7 @@ export class NumberColumn {

export class FloatColumn extends NumberColumn {
setValue(value?: number) {
const required = this.required && typeof this.value === "undefined";
const required = this.required && (typeof this.value === "undefined" || this.value == null);
const result = validateTiny(value, this.title, required);

if (result) {
Expand All @@ -188,7 +188,7 @@ export class FloatColumn extends NumberColumn {

export class TinyColumn extends NumberColumn {
setValue(value?: number) {
const required = this.required && typeof this.value === "undefined";
const required = this.required && (typeof this.value === "undefined" || this.value == null);
const result = validateTiny(value, this.title, required);

if (result) {
Expand All @@ -199,7 +199,7 @@ export class TinyColumn extends NumberColumn {

export class SmallColumn extends NumberColumn {
setValue(value?: number) {
const required = this.required && typeof this.value === "undefined";
const required = this.required && (typeof this.value === "undefined" || this.value == null);
const result = validateSmall(value, this.title, required);

if (result) {
Expand All @@ -210,7 +210,7 @@ export class SmallColumn extends NumberColumn {

export class IntColumn extends NumberColumn {
setValue(value?: number) {
const required = this.required && typeof this.value === "undefined";
const required = this.required && (typeof this.value === "undefined" || this.value == null);
const result = validateInt(value, this.title, required);

if (result) {
Expand All @@ -221,7 +221,7 @@ export class IntColumn extends NumberColumn {

export class LngColumn extends NumberColumn {
setValue(value?: number) {
const required = this.required && typeof this.value === "undefined";
const required = this.required && (typeof this.value === "undefined" || this.value == null);
const result = validateLng(value, this.title, required);

if (result) {
Expand All @@ -232,7 +232,7 @@ export class LngColumn extends NumberColumn {

export class LatColumn extends NumberColumn {
setValue(value?: number) {
const required = this.required && typeof this.value === "undefined";
const required = this.required && (typeof this.value === "undefined" || this.value == null);
const result = validateLat(value, this.title, required);

if (result) {
Expand Down Expand Up @@ -263,7 +263,7 @@ export class TimestampColumn {
return;
}

const required = this.required && typeof this.value === "undefined";
const required = this.required && (typeof this.value === "undefined" || this.value == null);
const result = validateTimestamp(value, this.title, required);

if (result) {
Expand Down Expand Up @@ -302,7 +302,7 @@ export class BooleanColumn {
return;
}

const required = this.required && typeof this.value === "undefined";
const required = this.required && (typeof this.value === "undefined" || this.value == null);
const result = validateBinary(value, this.title, required);

if (result) {
Expand Down

0 comments on commit 9e3532b

Please sign in to comment.