refactored .thens as try catch
This commit is contained in:
parent
b78fc7b9fb
commit
ccf2a3e7f0
|
@ -15,22 +15,27 @@ export const getWords = async () => {
|
||||||
return db
|
return db
|
||||||
.select("word")
|
.select("word")
|
||||||
.from("dictionary")
|
.from("dictionary")
|
||||||
.catch(error=>{throw error})
|
.catch(error => { throw error })
|
||||||
}
|
}
|
||||||
|
|
||||||
export const valueExistsInTable = async (table,column,value) =>{
|
export const valueExistsInTable = async (table, column, value) => {
|
||||||
|
try {
|
||||||
const number = await db(table)
|
const number = await db(table)
|
||||||
.count('* as count')
|
.count('* as count')
|
||||||
.where(column, value)
|
.where(column, value)
|
||||||
.catch(error => { throw error })
|
|
||||||
return number[0].count > 0
|
return number[0].count > 0
|
||||||
|
} catch (error) {
|
||||||
|
logger.error("valueExistsInTable failed!")
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export const todaysPromptAlreadyPublished = async () => {
|
export const todaysPromptAlreadyPublished = async () => {
|
||||||
return valueExistsInTable('published','date',isoDate())
|
return valueExistsInTable('published', 'date', isoDate())
|
||||||
}
|
}
|
||||||
|
|
||||||
export const wordIsAlreadyInBuffer = async (word) => {
|
export const wordIsAlreadyInBuffer = async (word) => {
|
||||||
return valueExistsInTable('buffer','word',word)
|
return valueExistsInTable('buffer', 'word', word)
|
||||||
}
|
}
|
|
@ -10,6 +10,7 @@ const blocklist = db.union([
|
||||||
|
|
||||||
export default async () => {
|
export default async () => {
|
||||||
logger.trace("getAcceptablePrompt called")
|
logger.trace("getAcceptablePrompt called")
|
||||||
|
try {
|
||||||
return db('dictionary')
|
return db('dictionary')
|
||||||
.select('*')
|
.select('*')
|
||||||
.where({
|
.where({
|
||||||
|
@ -22,5 +23,8 @@ export default async () => {
|
||||||
.whereRaw('length(word) > 3')
|
.whereRaw('length(word) > 3')
|
||||||
.whereNotNull('pronunciation')
|
.whereNotNull('pronunciation')
|
||||||
.orderByRaw('count desc')
|
.orderByRaw('count desc')
|
||||||
.catch(error=>{throw error})
|
} catch (error) {
|
||||||
|
logger.error("getAcceptablePrompts failed!")
|
||||||
|
throw error
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -37,27 +37,27 @@ const sampleRes = {
|
||||||
reactions: {},
|
reactions: {},
|
||||||
reactionEmojis: [],
|
reactionEmojis: [],
|
||||||
emojis: [],
|
emojis: [],
|
||||||
tags: [ 'micro365', 'writing', 'microfiction', 'vss', 'marmalade' ],
|
tags: ['micro365', 'writing', 'microfiction', 'vss', 'marmalade'],
|
||||||
fileIds: [],
|
fileIds: [],
|
||||||
files: [],
|
files: [],
|
||||||
replyId: null,
|
replyId: null,
|
||||||
renoteId: null
|
renoteId: null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async function insertPublished(res, word){
|
export default async function insertPublished(res, word) {
|
||||||
const childLogger = logger.child({res,word})
|
logger.trace("insertPublished called")
|
||||||
childLogger.trace("insertPublished called")
|
try {
|
||||||
return db('published')
|
return db('published')
|
||||||
.insert({
|
.insert({
|
||||||
id: res.createdNote.id,
|
id: res.createdNote.id,
|
||||||
word,
|
word,
|
||||||
date: isoDate(sampleRes.createdNote.createdAt)
|
date: isoDate(sampleRes.createdNote.createdAt)
|
||||||
})
|
})
|
||||||
.then(res => {
|
} catch (error) {
|
||||||
childLogger.trace("succesful insertion into table: published")
|
logger.trace("succesful insertion into table: published")
|
||||||
return res
|
throw error
|
||||||
})
|
}
|
||||||
.catch(error => {throw error})
|
|
||||||
}
|
}
|
||||||
//console.log(await insertPublished(sampleRes,'marmalade'))
|
//console.log(await insertPublished(sampleRes,'marmalade'))
|
|
@ -1,11 +1,17 @@
|
||||||
import { db } from "./db.mjs";
|
import { db } from "./db.mjs";
|
||||||
import { isoDate } from "../utilities.mjs";
|
import { isoDate } from "../utilities.mjs";
|
||||||
|
import logger from "../logger.mjs";
|
||||||
export default async function todaysPromptAlreadyPublished() {
|
export default async function todaysPromptAlreadyPublished() {
|
||||||
|
try {
|
||||||
const number = await db('published')
|
const number = await db('published')
|
||||||
.count('* as count')
|
.count('* as count')
|
||||||
.where('date', isoDate())
|
.where('date', isoDate())
|
||||||
.catch(error=>{throw error})
|
|
||||||
return number[0].count > 0
|
return number[0].count > 0
|
||||||
|
} catch (error) {
|
||||||
|
logger.error("todaysPromptAlreadyPublished failed!")
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//console.log(await todaysPromptAlreadyPublished())
|
//console.log(await todaysPromptAlreadyPublished())
|
||||||
|
|
Loading…
Reference in New Issue