mirror of
https://github.com/cheveguerra/bot-whatsapp.git
synced 2026-04-18 11:39:15 +00:00
fix(cli): 🔥 update instructions
This commit is contained in:
47
packages/database/src/json/index.js
Normal file
47
packages/database/src/json/index.js
Normal file
@@ -0,0 +1,47 @@
|
||||
const StormDB = require('stormdb')
|
||||
const { join } = require('path')
|
||||
|
||||
const engine = new StormDB.localFileEngine(join(process.cwd(), './db.stormdb'))
|
||||
|
||||
class JsonFileAdapter {
|
||||
db
|
||||
listHistory = []
|
||||
|
||||
constructor() {
|
||||
this.init().then()
|
||||
}
|
||||
|
||||
init() {
|
||||
return new Promise((resolve) => {
|
||||
this.db = new StormDB(engine)
|
||||
this.db.default({ history: [] })
|
||||
resolve(this.db)
|
||||
})
|
||||
}
|
||||
|
||||
getPrevByNumber = async (from) => {
|
||||
const response = await this.db.get('history')
|
||||
const { history } = response.state
|
||||
|
||||
if (!history.length) {
|
||||
return null
|
||||
}
|
||||
|
||||
const result = history.filter((res) => res.from === from).pop()
|
||||
|
||||
return {
|
||||
...result,
|
||||
}
|
||||
}
|
||||
|
||||
save = async (ctx) => {
|
||||
await this.db
|
||||
.get('history')
|
||||
.push({ ...ctx })
|
||||
.save()
|
||||
console.log('Guardado en DB...', ctx)
|
||||
this.listHistory.push(ctx)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = JsonFileAdapter
|
||||
Reference in New Issue
Block a user