Skip to content

Commit

Permalink
Merge pull request #125 from roqtech/dev
Browse files Browse the repository at this point in the history
Add file association and delete file associations
  • Loading branch information
junwatu authored Nov 22, 2023
2 parents 5d00a56 + df13a68 commit d0f81c3
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions pages/files/api.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,60 @@ const upfileStatus =async () => {
*/}

## File associations

<Callout type="info" emoji="ℹ️">
This endpoint is only available from the server side of your application.
</Callout>

### `createFileAssociation()`

Files usually belong to some other object. For instance, you may have PDFs which represent _"contracts"_. Or you may have images which are _"avatars"_ and so on. To simplify this, ROQ enables you to relate files with objects which are saved on your database. The advantage is that you don't need to add these relations to your own database. File associations will simplify the database schema.

<Tabs items={['JavaScript']}>
<Tab>
```ts
await roqServerClient.roqPlatform.asSuperAdmin().createFileAssociation({
data: {
entityName: "purchase_history",
entityReference: "3c0e2ce1-3105-447a-b214-ac1e0b1e7304",
fileId: "97eeb4da-d402-4a89-b034-bcb277b9e65c"
},
});
```
</Tab>
</Tabs>

| Parameter | Type | Description |
| ----------------- | ------ |-----------------|
| `fileId` | UUID | The ID of the file|
| `entityReference` | UUID | Reference (or ID) of the related entity in your database |
| `entityName` | string | Name of the object. This could be the name of the table in your database, e.g. _"purchase_history"_ |

### `deleteFileAssociations()`

Using this API will result in the deletion of any file associations.

<Tabs items={["JavaScript"]}>
<Tab>
```js
const delFileAssoc = await roqServerClient.roqPlatform.asSuperAdmin().deleteFileAssociations({
filter: {
id: {
equalTo: "7526d4b4-26db-4872-834d-68da2a1447e9"
}
}
})
```
</Tab>
</Tabs>

| Parameter | Type | Description |
| ----------------- | -------- |------------------------------------------------------------------------|
| `filter:id` | object | You can use `equalTo` or `valueIn` for the ID of the file associations |
| `filter:fileId` | object | You can use `equalTo` or `valueIn` for the ID of the files |


## File deletion

### `deleteFiles()`
Expand Down

2 comments on commit d0f81c3

@vercel
Copy link

@vercel vercel bot commented on d0f81c3 Nov 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on d0f81c3 Nov 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

beta-roq-doc – ./

beta-roq-doc-git-dev-techwriter.vercel.app
beta-roq-doc.vercel.app
beta-roq-doc-techwriter.vercel.app

Please sign in to comment.