Polarcraft/web/server/api/store/index.post.js
Xeovalyte 8121b9b975
Some checks failed
Build and Deploy / Deploy Web (push) Has been cancelled
Build and Deploy / Deploy Discord Bot (push) Has been cancelled
Lots of improvements and changes
2023-05-27 12:02:33 +02:00

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
});