SectionList on home screen with API
This commit is contained in:
@@ -11,31 +11,24 @@ Grid.mongo = mongoose.mongo
|
||||
@autobind
|
||||
export class DB {
|
||||
constructor() {
|
||||
mongoose.Promise = Promise
|
||||
mongoose.plugin(merge)
|
||||
}
|
||||
|
||||
connect(mongoUri, isProduction) {
|
||||
return mongoose
|
||||
.connect(mongoUri, {
|
||||
useMongoClient: true,
|
||||
config: { autoIndex: !isProduction },
|
||||
})
|
||||
.then((connection) => {
|
||||
this.connection = connection
|
||||
async connect(mongoUri, isProduction) {
|
||||
const connection = await mongoose.createConnection(mongoUri, {
|
||||
promiseLibrary: Promise,
|
||||
autoIndex: !isProduction,
|
||||
})
|
||||
|
||||
this.gridfs = Grid(connection.db)
|
||||
this.gridfs.findOneAsync = util.promisify(this.gridfs.findOne)
|
||||
this.gridfs.removeAsync = util.promisify(this.gridfs.remove)
|
||||
this.gridfs = Grid(connection.db)
|
||||
this.gridfs.findOneAsync = util.promisify(this.gridfs.findOne)
|
||||
this.gridfs.removeAsync = util.promisify(this.gridfs.remove)
|
||||
|
||||
this.User = connection.model("User", Schemas.userSchema)
|
||||
this.WorkItem = connection.model("WorkItem", Schemas.workItemSchema)
|
||||
this.Activity = connection.model("Activity", Schemas.activitySchema)
|
||||
this.Team = connection.model("Team", Schemas.teamSchema)
|
||||
this.Counter = connection.model("Counter", Schemas.counterSchema)
|
||||
|
||||
return Promise.resolve(this)
|
||||
})
|
||||
this.User = connection.model("User", Schemas.userSchema)
|
||||
this.WorkItem = connection.model("WorkItem", Schemas.workItemSchema)
|
||||
this.Activity = connection.model("Activity", Schemas.activitySchema)
|
||||
this.Team = connection.model("Team", Schemas.teamSchema)
|
||||
this.Counter = connection.model("Counter", Schemas.counterSchema)
|
||||
}
|
||||
|
||||
newObjectId(s) {
|
||||
@@ -43,17 +36,16 @@ export class DB {
|
||||
return new mongodb.ObjectID(s).toString()
|
||||
}
|
||||
|
||||
lookupToken(token, done) {
|
||||
this.User.findOne({ loginToken: token })
|
||||
.then((user) => {
|
||||
if (!user) {
|
||||
done(null, false)
|
||||
} else {
|
||||
done(null, user)
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
done(err)
|
||||
})
|
||||
async lookupToken(token, done) {
|
||||
try {
|
||||
const user = await this.User.findOne({ loginToken: token })
|
||||
if (!user) {
|
||||
done(null, false)
|
||||
} else {
|
||||
done(null, user)
|
||||
}
|
||||
} catch (err) {
|
||||
done(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user