add getLastBlockStore

This commit is contained in:
Barry Gitarts 2019-01-18 20:49:14 -05:00
parent a0a71ca97d
commit 4ec9180006
2 changed files with 12 additions and 3 deletions

View File

@ -34,6 +34,13 @@ export const getLpEventById = async id => {
const event = await lpCollection.query(
Q.where('event_id', id)
).fetch()
console.log({event})
return event
}
export const getLastBlockStored = async () => {
const col = await lpCollection.query().fetch()
const sorted = col.sort(
(a,b) => b.blockNumber - a.blockNumber
)
return sorted[0].blockNumber
}

View File

@ -5,7 +5,8 @@ const profilesCollection = database.collections.get('profiles')
export const addProfile = async data => {
return await database.action(async () => {
const res = await profilesCollection.create(profile => {
const { addr, canceled, commitTime, type, name, url, idProfile } = data
const { id, addr, canceled, commitTime, type, name, url, idProfile } = data
profile.eventId = id
profile.addr = addr
profile.canceled = canceled
profile.commitTime = Number(commitTime)
@ -21,7 +22,8 @@ export const addProfile = async data => {
export const batchAddProfiles = async profiles => {
const batch = profiles.map(data => {
return profilesCollection.prepareCreate(profile => {
const { addr, canceled, commitTime, type, name, url, idProfile } = data
const { id, addr, canceled, commitTime, type, name, url, idProfile } = data
profile.eventId = id
profile.addr = addr
profile.canceled = canceled
profile.commitTime = Number(commitTime)