Simplify getNow
This commit is contained in:
parent
c7952738b5
commit
42912040ff
|
@ -79,7 +79,7 @@ export default function EditSet() {
|
||||||
image = await setRepo.findOne({where: {name}}).then(s => s?.image)
|
image = await setRepo.findOne({where: {name}}).then(s => s?.image)
|
||||||
|
|
||||||
console.log(`${EditSet.name}.handleSubmit:`, {image})
|
console.log(`${EditSet.name}.handleSubmit:`, {image})
|
||||||
const [{now}] = await getNow()
|
const now = await getNow()
|
||||||
const saved = await setRepo.save({
|
const saved = await setRepo.save({
|
||||||
id: set.id,
|
id: set.id,
|
||||||
name,
|
name,
|
||||||
|
|
|
@ -66,7 +66,7 @@ export default function EditWorkout() {
|
||||||
}
|
}
|
||||||
|
|
||||||
const add = async () => {
|
const add = async () => {
|
||||||
const [{now}] = await getNow()
|
const now = await getNow()
|
||||||
await setRepo.save({
|
await setRepo.save({
|
||||||
...defaultSet,
|
...defaultSet,
|
||||||
name,
|
name,
|
||||||
|
|
|
@ -79,7 +79,7 @@ export default function SetList() {
|
||||||
}, [term, end, offset, sets])
|
}, [term, end, offset, sets])
|
||||||
|
|
||||||
const onAdd = useCallback(async () => {
|
const onAdd = useCallback(async () => {
|
||||||
const [{now}] = await getNow()
|
const now = await getNow()
|
||||||
let set = sets[0]
|
let set = sets[0]
|
||||||
if (!set) set = {...defaultSet}
|
if (!set) set = {...defaultSet}
|
||||||
set.created = now
|
set.created = now
|
||||||
|
|
|
@ -78,7 +78,7 @@ export default function StartPlan() {
|
||||||
)
|
)
|
||||||
|
|
||||||
const handleSubmit = async () => {
|
const handleSubmit = async () => {
|
||||||
const [{now}] = await getNow()
|
const now = await getNow()
|
||||||
const workout = counts[selected]
|
const workout = counts[selected]
|
||||||
const best = await getBestSet(workout.name)
|
const best = await getBestSet(workout.name)
|
||||||
delete best.id
|
delete best.id
|
||||||
|
|
|
@ -22,7 +22,7 @@ export default function StartPlanItem(props: Props) {
|
||||||
const {navigate} = useNavigation<NavigationProp<PlanPageParams>>()
|
const {navigate} = useNavigation<NavigationProp<PlanPageParams>>()
|
||||||
|
|
||||||
const undo = useCallback(async () => {
|
const undo = useCallback(async () => {
|
||||||
const [{now}] = await getNow()
|
const now = await getNow()
|
||||||
const created = now.split('T')[0]
|
const created = now.split('T')[0]
|
||||||
const first = await setRepo.findOne({
|
const first = await setRepo.findOne({
|
||||||
where: {
|
where: {
|
||||||
|
@ -47,7 +47,7 @@ export default function StartPlanItem(props: Props) {
|
||||||
)
|
)
|
||||||
|
|
||||||
const edit = async () => {
|
const edit = async () => {
|
||||||
const [{now}] = await getNow()
|
const now = await getNow()
|
||||||
const created = now.split('T')[0]
|
const created = now.split('T')[0]
|
||||||
const first = await setRepo.findOne({
|
const first = await setRepo.findOne({
|
||||||
where: {
|
where: {
|
||||||
|
|
5
db.ts
5
db.ts
|
@ -7,8 +7,9 @@ export const setRepo = AppDataSource.manager.getRepository(GymSet)
|
||||||
export const planRepo = AppDataSource.manager.getRepository(Plan)
|
export const planRepo = AppDataSource.manager.getRepository(Plan)
|
||||||
export const settingsRepo = AppDataSource.manager.getRepository(Settings)
|
export const settingsRepo = AppDataSource.manager.getRepository(Settings)
|
||||||
|
|
||||||
export const getNow = (): Promise<{now: string}[]> => {
|
export const getNow = async (): Promise<string> => {
|
||||||
return AppDataSource.manager.query(
|
const query = await AppDataSource.manager.query(
|
||||||
"SELECT STRFTIME('%Y-%m-%dT%H:%M:%S','now','localtime') AS now",
|
"SELECT STRFTIME('%Y-%m-%dT%H:%M:%S','now','localtime') AS now",
|
||||||
)
|
)
|
||||||
|
return query[0].now
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ import SetList from '../SetList'
|
||||||
import Settings from '../settings'
|
import Settings from '../settings'
|
||||||
|
|
||||||
jest.mock('../db.ts', () => ({
|
jest.mock('../db.ts', () => ({
|
||||||
getNow: () => Promise.resolve([{now: new Date().toISOString()}]),
|
getNow: () => Promise.resolve(new Date().toISOString()),
|
||||||
setRepo: {
|
setRepo: {
|
||||||
findOne: () => Promise.resolve({}),
|
findOne: () => Promise.resolve({}),
|
||||||
save: jest.fn(() => Promise.resolve({})),
|
save: jest.fn(() => Promise.resolve({})),
|
||||||
|
|
|
@ -16,7 +16,7 @@ jest.mock('@react-navigation/native', () => ({
|
||||||
}))
|
}))
|
||||||
|
|
||||||
jest.mock('../db.ts', () => ({
|
jest.mock('../db.ts', () => ({
|
||||||
getNow: () => Promise.resolve([{now: new Date().toISOString()}]),
|
getNow: () => Promise.resolve(new Date().toISOString()),
|
||||||
setRepo: {
|
setRepo: {
|
||||||
find: () =>
|
find: () =>
|
||||||
Promise.resolve([
|
Promise.resolve([
|
||||||
|
|
|
@ -14,7 +14,7 @@ jest.mock('../best.service.ts', () => ({
|
||||||
}))
|
}))
|
||||||
|
|
||||||
jest.mock('../db.ts', () => ({
|
jest.mock('../db.ts', () => ({
|
||||||
getNow: () => Promise.resolve([{now: new Date().toISOString()}]),
|
getNow: () => Promise.resolve(new Date().toISOString()),
|
||||||
setRepo: {
|
setRepo: {
|
||||||
findOne: () => Promise.resolve({}),
|
findOne: () => Promise.resolve({}),
|
||||||
save: () => Promise.resolve(),
|
save: () => Promise.resolve(),
|
||||||
|
|
Loading…
Reference in New Issue
Block a user