Simplify getNow

This commit is contained in:
Brandon Presley 2023-01-04 13:24:49 +13:00
parent c7952738b5
commit 42912040ff
9 changed files with 12 additions and 11 deletions

View File

@ -79,7 +79,7 @@ export default function EditSet() {
image = await setRepo.findOne({where: {name}}).then(s => s?.image)
console.log(`${EditSet.name}.handleSubmit:`, {image})
const [{now}] = await getNow()
const now = await getNow()
const saved = await setRepo.save({
id: set.id,
name,

View File

@ -66,7 +66,7 @@ export default function EditWorkout() {
}
const add = async () => {
const [{now}] = await getNow()
const now = await getNow()
await setRepo.save({
...defaultSet,
name,

View File

@ -79,7 +79,7 @@ export default function SetList() {
}, [term, end, offset, sets])
const onAdd = useCallback(async () => {
const [{now}] = await getNow()
const now = await getNow()
let set = sets[0]
if (!set) set = {...defaultSet}
set.created = now

View File

@ -78,7 +78,7 @@ export default function StartPlan() {
)
const handleSubmit = async () => {
const [{now}] = await getNow()
const now = await getNow()
const workout = counts[selected]
const best = await getBestSet(workout.name)
delete best.id

View File

@ -22,7 +22,7 @@ export default function StartPlanItem(props: Props) {
const {navigate} = useNavigation<NavigationProp<PlanPageParams>>()
const undo = useCallback(async () => {
const [{now}] = await getNow()
const now = await getNow()
const created = now.split('T')[0]
const first = await setRepo.findOne({
where: {
@ -47,7 +47,7 @@ export default function StartPlanItem(props: Props) {
)
const edit = async () => {
const [{now}] = await getNow()
const now = await getNow()
const created = now.split('T')[0]
const first = await setRepo.findOne({
where: {

5
db.ts
View File

@ -7,8 +7,9 @@ export const setRepo = AppDataSource.manager.getRepository(GymSet)
export const planRepo = AppDataSource.manager.getRepository(Plan)
export const settingsRepo = AppDataSource.manager.getRepository(Settings)
export const getNow = (): Promise<{now: string}[]> => {
return AppDataSource.manager.query(
export const getNow = async (): Promise<string> => {
const query = await AppDataSource.manager.query(
"SELECT STRFTIME('%Y-%m-%dT%H:%M:%S','now','localtime') AS now",
)
return query[0].now
}

View File

@ -10,7 +10,7 @@ import SetList from '../SetList'
import Settings from '../settings'
jest.mock('../db.ts', () => ({
getNow: () => Promise.resolve([{now: new Date().toISOString()}]),
getNow: () => Promise.resolve(new Date().toISOString()),
setRepo: {
findOne: () => Promise.resolve({}),
save: jest.fn(() => Promise.resolve({})),

View File

@ -16,7 +16,7 @@ jest.mock('@react-navigation/native', () => ({
}))
jest.mock('../db.ts', () => ({
getNow: () => Promise.resolve([{now: new Date().toISOString()}]),
getNow: () => Promise.resolve(new Date().toISOString()),
setRepo: {
find: () =>
Promise.resolve([

View File

@ -14,7 +14,7 @@ jest.mock('../best.service.ts', () => ({
}))
jest.mock('../db.ts', () => ({
getNow: () => Promise.resolve([{now: new Date().toISOString()}]),
getNow: () => Promise.resolve(new Date().toISOString()),
setRepo: {
findOne: () => Promise.resolve({}),
save: () => Promise.resolve(),