Skip to content

Commit

Permalink
feat(module): implemented support for revisions
Browse files Browse the repository at this point in the history
  • Loading branch information
Intevel committed Oct 6, 2022
1 parent 5814b41 commit 5771b0a
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/runtime/composables/useDirectusAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,14 @@ export const useDirectusAuth = () => {
)
}
if (config.directus.fetchUserParams) {
var res = await directus<{ data: DirectusUser }>('/users/me', {
const res = await directus<{ data: DirectusUser }>('/users/me', {
params: config.directus.fetchUserParams
})
setUser(res.data)
} else {
var res = await directus<{ data: DirectusUser }>('/users/me')
const res = await directus<{ data: DirectusUser }>('/users/me')
setUser(res.data)
}
setUser(res.data)
} catch (e) {
setToken(null)
}
Expand Down
41 changes: 41 additions & 0 deletions src/runtime/composables/useDirectusRevisions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { DirectusQueryParams, DirectusRevision } from '../types'
import { useDirectus } from './useDirectus'

export const useDirectusRevisions = () => {
const directus = useDirectus()

const getRevisions = async <T>(data: {
params: DirectusQueryParams;
}): Promise<T[]> => {
if (data.params?.filter) {
(data.params.filter as unknown) = JSON.stringify(data.params.filter)
}
if (data.params?.deep) {
(data.params.deep as unknown) = JSON.stringify(data.params.deep)
}
const revisions = await directus<{ data: T[] }>('/revisions', {
method: 'GET',
params: data.params
})
return revisions.data
}

const getRevisionById = async <T>(data: {
id: number;
params: DirectusQueryParams;
}): Promise<T[]> => {
const revisions = await directus<{ data: T[] }>(
`/revisions/${data.id}`,
{
method: 'GET',
params: data.params
}
)
return revisions.data
}

return {
getRevisionById,
getRevisions
}
}
10 changes: 10 additions & 0 deletions src/runtime/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,13 @@ export interface DirectusCollectionUpdate {
collection: string;
meta: DirectusCollectionMeta;
}

export interface DirectusRevision {
id: number;
activity?: any;
collection: string;
item?: string;
data?: Object;
delta?: Object;
parent?: any;
}

0 comments on commit 5771b0a

Please sign in to comment.