feat: duplicate document
This commit is contained in:
@ -1,4 +1,3 @@
|
|||||||
<!-- eslint-disable no-console -->
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
collection: {
|
collection: {
|
||||||
@ -68,8 +67,8 @@ function editDocument(document: any) {
|
|||||||
selectedDocument.value = { ...document }
|
selectedDocument.value = { ...document }
|
||||||
}
|
}
|
||||||
|
|
||||||
async function saveDocument() {
|
async function saveDocument(document: any) {
|
||||||
await rpc.createDocument(props.collection, selectedDocument.value)
|
await rpc.createDocument(props.collection, document)
|
||||||
editing.value = false
|
editing.value = false
|
||||||
selectedDocument.value = undefined
|
selectedDocument.value = undefined
|
||||||
documents.value = await rpc.listDocuments(props.collection)
|
documents.value = await rpc.listDocuments(props.collection)
|
||||||
@ -138,6 +137,7 @@ async function deleteDocument(document: any) {
|
|||||||
<template v-else>
|
<template v-else>
|
||||||
<NIconButton icon="carbon-edit" @click="editDocument(document)" />
|
<NIconButton icon="carbon-edit" @click="editDocument(document)" />
|
||||||
<NIconButton icon="carbon-delete" @click="deleteDocument(document)" />
|
<NIconButton icon="carbon-delete" @click="deleteDocument(document)" />
|
||||||
|
<NIconButton icon="carbon-document-multiple-02" @click="saveDocument(document)" />
|
||||||
</template>
|
</template>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
@ -148,7 +148,7 @@ async function deleteDocument(document: any) {
|
|||||||
<input v-else placeholder="ObjectId(_id)" disabled>
|
<input v-else placeholder="ObjectId(_id)" disabled>
|
||||||
</td>
|
</td>
|
||||||
<td flex justify-center gap2 class="actions">
|
<td flex justify-center gap2 class="actions">
|
||||||
<NIconButton icon="carbon-save" @click="saveDocument" />
|
<NIconButton icon="carbon-save" @click="saveDocument(selectedDocument)" />
|
||||||
<NIconButton icon="carbon-close" @click="discardEditing" />
|
<NIconButton icon="carbon-close" @click="discardEditing" />
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
@ -23,7 +23,8 @@ export function setupDatabaseRPC({ options }: NuxtDevtoolsServerContext): any {
|
|||||||
},
|
},
|
||||||
|
|
||||||
async createDocument(collection: string, data: any) {
|
async createDocument(collection: string, data: any) {
|
||||||
return await mongoose.connection.db.collection(collection).insertOne(data)
|
const { _id, ...rest } = data
|
||||||
|
return await mongoose.connection.db.collection(collection).insertOne(rest)
|
||||||
},
|
},
|
||||||
async listDocuments(collection: string) {
|
async listDocuments(collection: string) {
|
||||||
return await mongoose.connection.db.collection(collection).find().toArray()
|
return await mongoose.connection.db.collection(collection).find().toArray()
|
||||||
|
|||||||
Reference in New Issue
Block a user