Skip to content

Commit

Permalink
Upload artifact with groups option
Browse files Browse the repository at this point in the history
  • Loading branch information
yunusefendi52 committed Apr 28, 2024
1 parent c120292 commit 1fed3b9
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
31 changes: 29 additions & 2 deletions components/AppFileUpload.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,18 @@
<label for="releasenotes">Release Notes</label>
<InputText id="releasenotes" v-model="releaseNotes" aria-describedby="releasenotes-help" />
</div>
<div class="flex flex-column gap-2">
<label for="releasenotes">Groups</label>
<MultiSelect v-model="selectedGroup" display="chip" :options="groups" optionLabel="name"
placeholder="Select Groups" />
</div>
<Button label="Upload" @click="submit" :loading="isPending" />
</div>
</template>

<script setup lang="ts">
import { UpdateGroupsRequest } from '~/server/api/update-artifact-groups.put';
const releaseNotes = ref<string | null>(null)
const dialogRef = inject<any>('dialogRef');
const osType = ref<OsType | null>(null)
Expand All @@ -26,9 +33,28 @@ onMounted(() => {
const mimeTypeFromOsType = computed(() => getMimeTypeFromosType(osType.value ?? 'android'))
const fileRef = ref<HTMLInputElement | null>(null)
const { data: appGroups } = useFetch('/api/groups/list-groups', {
query: {
appName: appName,
orgName: orgName,
},
})
const groups = computed(() => appGroups.value ?? [])
const selectedGroup = ref<any[]>()
const { mutateAsync, isPending } = useMutation({
mutationFn: async (file: File) => {
await onUpload(file)
const { artifactId } = await onUpload(file)
const groupIds = selectedGroup.value?.map(e => e.id) ?? []
if (artifactId && groupIds && groupIds.length) {
await $fetch('/api/update-artifact-groups', {
body: {
artifactId: artifactId,
groupIds: groupIds,
} satisfies UpdateGroupsRequest,
method: 'put',
})
}
},
onSuccess: () => {
if (fileRef.value) {
Expand Down Expand Up @@ -64,13 +90,14 @@ const onUpload = async (file: File) => {
body: file,
redirect: "follow",
})
await $fetch('/api/artifacts/upload-artifact-url', {
const data = await $fetch('/api/artifacts/upload-artifact-url', {
method: 'post',
body: {
key: key,
...prop.value,
releaseNotes: releaseNotes.value,
},
})
return data
};
</script>
1 change: 1 addition & 0 deletions components/Releases.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const upload = () => {
props,
orgName: props.orgName,
appName: props.appName,
artifactId:
},
onClose: (o) => {
if (o?.data?.success) {
Expand Down
4 changes: 4 additions & 0 deletions server/api/artifacts/upload-artifact-url.post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,8 @@ export default defineEventHandler(async (event) => {
Bucket: s3BucketName,
Key: temp,
}))

return {
artifactId: artifactsId,
}
})
9 changes: 8 additions & 1 deletion server/api/groups/list-groups.get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@ import { takeUniqueOrThrow } from "../detail-app.get"
import { and, eq } from "drizzle-orm"

export default defineEventHandler(async (event) => {
const { appName, orgName } = getQuery(event)
const query = getQuery(event)
const orgName = query.orgName?.toString()
const appName = query.appName?.toString()
if (!orgName || !appName) {
setResponseStatus(event, 400)
return
}

const db = event.context.drizzle
const userId = event.context.auth.userId
const userOrg = await db.select({
Expand Down

0 comments on commit 1fed3b9

Please sign in to comment.