Respond to PR comments.
This commit is contained in:
parent
8a49953449
commit
c64d76eb84
3 changed files with 14 additions and 12 deletions
|
@ -8,6 +8,7 @@ const DOUBLE_SEPARATOR = `${SEPARATOR}${SEPARATOR}`
|
||||||
const ROW_ID_REGEX = /^\[.*]$/g
|
const ROW_ID_REGEX = /^\[.*]$/g
|
||||||
const ENCODED_SPACE = encodeURIComponent(" ")
|
const ENCODED_SPACE = encodeURIComponent(" ")
|
||||||
const ISO_DATE_REGEX = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z$/
|
const ISO_DATE_REGEX = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z$/
|
||||||
|
const TIME_REGEX = /^(?:\d{2}:)?(?:\d{2}:)(?:\d{2})$/
|
||||||
|
|
||||||
export function isExternalTableID(tableId: string) {
|
export function isExternalTableID(tableId: string) {
|
||||||
return tableId.startsWith(DocumentType.DATASOURCE + SEPARATOR)
|
return tableId.startsWith(DocumentType.DATASOURCE + SEPARATOR)
|
||||||
|
@ -147,6 +148,10 @@ export function isValidFilter(value: any) {
|
||||||
return value != null && value !== ""
|
return value != null && value !== ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isValidTime(value: string) {
|
||||||
|
return TIME_REGEX.test(value)
|
||||||
|
}
|
||||||
|
|
||||||
export function sqlLog(client: string, query: string, values?: any[]) {
|
export function sqlLog(client: string, query: string, values?: any[]) {
|
||||||
if (!environment.SQL_LOGGING_ENABLE) {
|
if (!environment.SQL_LOGGING_ENABLE) {
|
||||||
return
|
return
|
||||||
|
|
|
@ -99,19 +99,17 @@ export async function processAutoColumn(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function processDeafultValues(table: Table, row: Row) {
|
async function processDefaultValues(table: Table, row: Row) {
|
||||||
const ctx: { ["Current User"]?: User; user?: User } = {}
|
const ctx: { ["Current User"]?: User; user?: User } = {}
|
||||||
|
|
||||||
const identity = context.getIdentity()
|
const identity = context.getIdentity()
|
||||||
if (identity) {
|
if (identity?._id && identity.type === IdentityType.USER) {
|
||||||
if (identity._id && identity.type === IdentityType.USER) {
|
|
||||||
const user = await cache.user.getUser(identity._id)
|
const user = await cache.user.getUser(identity._id)
|
||||||
delete user.password
|
delete user.password
|
||||||
|
|
||||||
ctx["Current User"] = user
|
ctx["Current User"] = user
|
||||||
ctx.user = user
|
ctx.user = user
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
for (let [key, schema] of Object.entries(table.schema)) {
|
for (let [key, schema] of Object.entries(table.schema)) {
|
||||||
if ("default" in schema && schema.default != null && row[key] == null) {
|
if ("default" in schema && schema.default != null && row[key] == null) {
|
||||||
|
@ -221,7 +219,7 @@ export async function inputProcessing(
|
||||||
}
|
}
|
||||||
|
|
||||||
await processAutoColumn(userId, table, clonedRow, opts)
|
await processAutoColumn(userId, table, clonedRow, opts)
|
||||||
await processDeafultValues(table, clonedRow)
|
await processDefaultValues(table, clonedRow)
|
||||||
|
|
||||||
return { table, row: clonedRow }
|
return { table, row: clonedRow }
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
|
import { sql } from "@budibase/backend-core"
|
||||||
import { FieldType } from "@budibase/types"
|
import { FieldType } from "@budibase/types"
|
||||||
|
|
||||||
const TIME_REGEX = /^(?:\d{2}:)?(?:\d{2}:)(?:\d{2})$/
|
|
||||||
|
|
||||||
const parseArrayString = (value: any) => {
|
const parseArrayString = (value: any) => {
|
||||||
if (typeof value === "string") {
|
if (typeof value === "string") {
|
||||||
if (value === "") {
|
if (value === "") {
|
||||||
|
@ -117,7 +116,7 @@ export const TYPE_TRANSFORM_MAP: any = {
|
||||||
parse: (date: any) => {
|
parse: (date: any) => {
|
||||||
if (date instanceof Date) {
|
if (date instanceof Date) {
|
||||||
return date.toISOString()
|
return date.toISOString()
|
||||||
} else if (typeof date === "string" && TIME_REGEX.test(date)) {
|
} else if (typeof date === "string" && sql.utils.isValidTime(date)) {
|
||||||
return date
|
return date
|
||||||
} else {
|
} else {
|
||||||
const parsed = new Date(date)
|
const parsed = new Date(date)
|
||||||
|
|
Loading…
Reference in a new issue