liquid-funding/app/actions/profiles.js

38 lines
1.1 KiB
JavaScript
Raw Normal View History

2019-01-16 20:50:49 +00:00
import { Q } from '@nozbe/watermelondb'
import database from '../db'
const profilesCollection = database.collections.get('profiles')
export const addProfile = async data => {
await database.action(async () => {
const res = await profilesCollection.create(profile => {
const { addr, canceled, commitTime, type, name, url, idProfile } = data
//TODO add assignemnts
})
return res
})
}
export const batchAddProfiles = async profiles => {
const batch = profiles.map(data => {
return profilesCollection.prepareCreate(profile => {
const { addr, canceled, commitTime, type, name, url, idProfile } = data
profile.addr = addr
profile.canceled = canceled
2019-01-17 19:18:09 +00:00
profile.commitTime = Number(commitTime)
2019-01-16 20:50:49 +00:00
profile.type = type
profile.name = name
profile.url = url
2019-01-17 19:18:09 +00:00
profile.idProfile = Number(idProfile)
2019-01-16 20:50:49 +00:00
})
})
console.log({batch})
return await database.action(async () => await database.batch(...batch))
}
export const getProfileById = async id => {
const event = await profilesCollection.query(
Q.where('id_profile', id)
).fetch()
return event
}