14 lines
486 B
JavaScript
14 lines
486 B
JavaScript
|
import { ObjectId } from "mongodb";
|
||
|
|
||
|
export default defineEventHandler(async (event) => {
|
||
|
const { coords, name, items, id } = await readBody(event)
|
||
|
|
||
|
const user = await getAuth(event)
|
||
|
|
||
|
const storesColl = db.collection('stores');
|
||
|
|
||
|
const { value: store } = await storesColl.findOneAndUpdate({ _id: id ? new ObjectId(id) : new ObjectId() }, { $set: { coords: coords, name: name, items: items, ownerId: user._id, } }, { returnDocument: 'after', upsert: true })
|
||
|
|
||
|
return store
|
||
|
});
|