🐛 (sheets) Convert to base options before changing action
This commit is contained in:
@@ -56,24 +56,29 @@ export const GoogleSheetsSettingsBody = ({
|
|||||||
onOptionsChange({ ...options, sheetId })
|
onOptionsChange({ ...options, sheetId })
|
||||||
|
|
||||||
const handleActionChange = (action: GoogleSheetsAction) => {
|
const handleActionChange = (action: GoogleSheetsAction) => {
|
||||||
|
const baseOptions = {
|
||||||
|
credentialsId: options.credentialsId,
|
||||||
|
spreadsheetId: options.spreadsheetId,
|
||||||
|
sheetId: options.sheetId,
|
||||||
|
}
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case GoogleSheetsAction.GET: {
|
case GoogleSheetsAction.GET: {
|
||||||
const newOptions: GoogleSheetsGetOptions = {
|
const newOptions: GoogleSheetsGetOptions = {
|
||||||
...options,
|
...baseOptions,
|
||||||
...defaultGoogleSheetsGetOptions,
|
...defaultGoogleSheetsGetOptions,
|
||||||
}
|
}
|
||||||
return onOptionsChange({ ...newOptions })
|
return onOptionsChange({ ...newOptions })
|
||||||
}
|
}
|
||||||
case GoogleSheetsAction.INSERT_ROW: {
|
case GoogleSheetsAction.INSERT_ROW: {
|
||||||
const newOptions: GoogleSheetsInsertRowOptions = {
|
const newOptions: GoogleSheetsInsertRowOptions = {
|
||||||
...options,
|
...baseOptions,
|
||||||
...defaultGoogleSheetsInsertOptions,
|
...defaultGoogleSheetsInsertOptions,
|
||||||
}
|
}
|
||||||
return onOptionsChange({ ...newOptions })
|
return onOptionsChange({ ...newOptions })
|
||||||
}
|
}
|
||||||
case GoogleSheetsAction.UPDATE_ROW: {
|
case GoogleSheetsAction.UPDATE_ROW: {
|
||||||
const newOptions: GoogleSheetsUpdateRowOptions = {
|
const newOptions: GoogleSheetsUpdateRowOptions = {
|
||||||
...options,
|
...baseOptions,
|
||||||
...defaultGoogleSheetsUpdateOptions,
|
...defaultGoogleSheetsUpdateOptions,
|
||||||
}
|
}
|
||||||
return onOptionsChange({ ...newOptions })
|
return onOptionsChange({ ...newOptions })
|
||||||
|
|||||||
@@ -8,11 +8,11 @@ import {
|
|||||||
Group,
|
Group,
|
||||||
InputBlockType,
|
InputBlockType,
|
||||||
PublicTypebot,
|
PublicTypebot,
|
||||||
publicTypebotSchema,
|
|
||||||
Theme,
|
Theme,
|
||||||
Typebot,
|
Typebot,
|
||||||
|
typebotSchema,
|
||||||
} from 'models'
|
} from 'models'
|
||||||
import { isNotDefined } from 'utils'
|
import { isDefined, isNotDefined } from 'utils'
|
||||||
import { promptAndSetEnvironment } from './utils'
|
import { promptAndSetEnvironment } from './utils'
|
||||||
import { detailedDiff } from 'deep-object-diff'
|
import { detailedDiff } from 'deep-object-diff'
|
||||||
|
|
||||||
@@ -78,18 +78,22 @@ const fixBlocks = (
|
|||||||
}) as Block[]
|
}) as Block[]
|
||||||
}
|
}
|
||||||
|
|
||||||
const fixBrokenBlockOption = (option: BlockOptions, blockType: BlockType) =>
|
const fixBrokenBlockOption = (options: BlockOptions, blockType: BlockType) =>
|
||||||
removeUndefinedFromObject({
|
removeUndefinedFromObject({
|
||||||
...option,
|
...options,
|
||||||
sheetId:
|
sheetId:
|
||||||
'sheetId' in option && option.sheetId
|
'sheetId' in options && isDefined(options.sheetId)
|
||||||
? option.sheetId.toString()
|
? options.sheetId.toString()
|
||||||
|
: undefined,
|
||||||
|
step:
|
||||||
|
'step' in options && isDefined(options.step) ? options.step : undefined,
|
||||||
|
value:
|
||||||
|
'value' in options && isDefined(options.value)
|
||||||
|
? options.value
|
||||||
: undefined,
|
: undefined,
|
||||||
step: 'step' in option && option.step ? option.step : undefined,
|
|
||||||
value: 'value' in option && option.value ? option.value : undefined,
|
|
||||||
retryMessageContent: fixRetryMessageContent(
|
retryMessageContent: fixRetryMessageContent(
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
option.retryMessageContent,
|
options.retryMessageContent,
|
||||||
blockType
|
blockType
|
||||||
),
|
),
|
||||||
}) as BlockOptions
|
}) as BlockOptions
|
||||||
@@ -121,7 +125,18 @@ const fixTypebots = async () => {
|
|||||||
log: [{ emit: 'event', level: 'query' }, 'info', 'warn', 'error'],
|
log: [{ emit: 'event', level: 'query' }, 'info', 'warn', 'error'],
|
||||||
})
|
})
|
||||||
|
|
||||||
const typebots = await prisma.publicTypebot.findMany()
|
const twoDaysAgo = new Date()
|
||||||
|
twoDaysAgo.setDate(twoDaysAgo.getDate() - 2)
|
||||||
|
|
||||||
|
const typebots = await prisma.typebot.findMany({
|
||||||
|
where: {
|
||||||
|
updatedAt: {
|
||||||
|
gte: twoDaysAgo,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
writeFileSync('logs/typebots.json', JSON.stringify(typebots))
|
||||||
|
|
||||||
const total = typebots.length
|
const total = typebots.length
|
||||||
let totalFixed = 0
|
let totalFixed = 0
|
||||||
@@ -135,7 +150,7 @@ const fixTypebots = async () => {
|
|||||||
(progress / total) * 100
|
(progress / total) * 100
|
||||||
)}%) (${totalFixed} fixed typebots)`
|
)}%) (${totalFixed} fixed typebots)`
|
||||||
)
|
)
|
||||||
const parser = publicTypebotSchema.safeParse({
|
const parser = typebotSchema.safeParse({
|
||||||
...typebot,
|
...typebot,
|
||||||
updatedAt: new Date(typebot.updatedAt),
|
updatedAt: new Date(typebot.updatedAt),
|
||||||
createdAt: new Date(typebot.createdAt),
|
createdAt: new Date(typebot.createdAt),
|
||||||
@@ -143,18 +158,15 @@ const fixTypebots = async () => {
|
|||||||
if ('error' in parser) {
|
if ('error' in parser) {
|
||||||
const fixedTypebot = {
|
const fixedTypebot = {
|
||||||
...fixTypebot(typebot as Typebot | PublicTypebot),
|
...fixTypebot(typebot as Typebot | PublicTypebot),
|
||||||
updatedAt: new Date(typebot.updatedAt),
|
updatedAt: new Date(),
|
||||||
createdAt: new Date(typebot.createdAt),
|
createdAt: new Date(typebot.createdAt),
|
||||||
}
|
}
|
||||||
publicTypebotSchema.parse(fixedTypebot)
|
typebotSchema.parse(fixedTypebot)
|
||||||
fixedTypebots.push(fixedTypebot)
|
fixedTypebots.push(fixedTypebot)
|
||||||
totalFixed += 1
|
totalFixed += 1
|
||||||
diffs.push({
|
diffs.push({
|
||||||
id: typebot.id,
|
id: typebot.id,
|
||||||
failedObject: resolve(
|
failedObject: resolve(parser.error.issues[0].path.join('.'), typebot),
|
||||||
parser.error.issues[0].path.join('.'),
|
|
||||||
fixedTypebot
|
|
||||||
),
|
|
||||||
...detailedDiff(typebot, fixedTypebot),
|
...detailedDiff(typebot, fixedTypebot),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -184,26 +196,4 @@ const fixTypebots = async () => {
|
|||||||
await prisma.$transaction(queries)
|
await prisma.$transaction(queries)
|
||||||
}
|
}
|
||||||
|
|
||||||
// export const parseZodError = (parser: any) => {
|
|
||||||
// if ('error' in parser) {
|
|
||||||
// console.log(
|
|
||||||
// parser.error.issues.map((issue) =>
|
|
||||||
// JSON.stringify({
|
|
||||||
// message: issue.message,
|
|
||||||
// path: issue.path,
|
|
||||||
// })
|
|
||||||
// )
|
|
||||||
// )
|
|
||||||
// writeFileSync(
|
|
||||||
// 'failedObject.json',
|
|
||||||
// JSON.stringify(
|
|
||||||
// resolve(parser.error.issues[0].path.join('.'), fixedTypebot)
|
|
||||||
// )
|
|
||||||
// )
|
|
||||||
// writeFileSync('failedTypebot.json', JSON.stringify(fixedTypebot))
|
|
||||||
// writeFileSync('issue.json', JSON.stringify(parser.error.issues))
|
|
||||||
// exit()
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
fixTypebots()
|
fixTypebots()
|
||||||
|
|||||||
Reference in New Issue
Block a user