mirror of
https://github.com/overleaf/overleaf.git
synced 2024-10-31 21:21:03 -04:00
19 lines
519 B
CoffeeScript
19 lines
519 B
CoffeeScript
|
mongojs = require("../../mongojs")
|
||
|
db = mongojs.db
|
||
|
ObjectId = mongojs.ObjectId
|
||
|
|
||
|
module.exports = RoomManager =
|
||
|
findOrCreateRoom: (query, callback = (error, room) ->) ->
|
||
|
if query.project_id? and query.project_id not instanceof ObjectId
|
||
|
query.project_id = ObjectId(query.project_id)
|
||
|
|
||
|
db.rooms.findOne query, (error, room) ->
|
||
|
return callback(error) if error?
|
||
|
if room?
|
||
|
callback null, room
|
||
|
else
|
||
|
db.rooms.save query, (error, room) ->
|
||
|
return callback(error) if error?
|
||
|
callback null, room
|
||
|
|