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)
|
||||
|
||||
console.log(`${EditSet.name}.handleSubmit:`, {image})
|
||||
const [{now}] = await getNow()
|
||||
const now = await getNow()
|
||||
const saved = await setRepo.save({
|
||||
id: set.id,
|
||||
name,
|
||||
|
|
|
@ -66,7 +66,7 @@ export default function EditWorkout() {
|
|||
}
|
||||
|
||||
const add = async () => {
|
||||
const [{now}] = await getNow()
|
||||
const now = await getNow()
|
||||
await setRepo.save({
|
||||
...defaultSet,
|
||||
name,
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
5
db.ts
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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({})),
|
||||
|
|
|
@ -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([
|
||||
|
|
|
@ -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(),
|
||||
|
|
Loading…
Reference in New Issue
Block a user