Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/features/sync/components/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const MappingTableRow = ({ openConfirmDialog }: { openConfirmDialog: (id?: strin
mapItem.fileChannelValue?.[0],
)}
onChange={(val) => onUserSelectorValueChange(val, index)}
disabled={!!mapItem.status}
disabled={!!mapItem?.id || mapItem.status === null}
options={unselectedChannelList || {}}
/>
</td>
Expand All @@ -93,7 +93,7 @@ const MappingTableRow = ({ openConfirmDialog }: { openConfirmDialog: (id?: strin
onChange={(val) => onDropboxFolderChange(val, index)}
options={tempFolders || []}
placeholder="Search Dropbox folder"
disabled={!!mapItem.status}
disabled={!!mapItem?.id || mapItem.status === null}
/>
</td>
<td className="w-[150px] whitespace-nowrap px-6 py-2 text-gray-500 text-sm">
Expand Down
18 changes: 16 additions & 2 deletions src/features/sync/lib/MapFiles.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { and, asc, eq, isNotNull, isNull, sql } from 'drizzle-orm'
import { and, asc, eq, isNotNull, isNull, or, sql } from 'drizzle-orm'
import httpStatus from 'http-status'
import { ApiError } from 'node_modules/copilot-node-sdk/dist/codegen/api'
import z from 'zod'
Expand All @@ -16,6 +16,7 @@ import {
type FileSyncUpdatePayload,
fileFolderSync,
} from '@/db/schema/fileFolderSync.schema'
import APIError from '@/errors/APIError'
import type {
DropboxFileListFolderResultEntries,
MapList,
Expand Down Expand Up @@ -189,7 +190,11 @@ export class MapFilesService extends AuthenticatedDropboxService {
.where(
and(
eq(channelSync.portalId, this.user.portalId),
eq(channelSync.assemblyChannelId, payload.assemblyChannelId),
or(
eq(channelSync.assemblyChannelId, payload.assemblyChannelId),
eq(channelSync.dbxRootPath, payload.dbxRootPath),
),
isNull(channelSync.deletedAt),
),
)
logger.info('MapFilesService#getOrCreateChannelMap :: Got channel map', channel)
Expand All @@ -200,6 +205,15 @@ export class MapFilesService extends AuthenticatedDropboxService {
.returning()
channel = newChannel[0]
logger.info('MapFilesService#getOrCreateChannelMap :: Created channel map', channel)
} else {
if (
channel.assemblyChannelId !== payload.assemblyChannelId ||
channel.dbxRootPath !== payload.dbxRootPath
)
throw new APIError(
'Mapping already exists for the given file channel or dropbox folder',
httpStatus.BAD_REQUEST,
)
}

return channel
Expand Down
12 changes: 10 additions & 2 deletions src/helper/fetcher.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,35 @@ export const postFetcher = async (
headers: Record<string, string>,
options: Record<string, string>,
) => {
return await fetch(url, {
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
...headers,
},
...options,
})
if (!response.ok) {
throw new Error('Failed to post data')
}
return response
}

export const deleteFetcher = async (
url: string,
headers: Record<string, string>,
options: Record<string, string>,
) => {
return await fetch(url, {
const response = await fetch(url, {
method: 'DELETE',
headers: {
'Content-Type': 'application/json',
...headers,
},
...options,
})
if (!response.ok) {
throw new Error('Failed to delete data')
}
return response
}