Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ This changelog follows the principles of [Keep a Changelog](https://keepachangel

### Added

- Guestbooke: Added `editGuestbook` use case.
- Guestbooks: Added `getGuestbookResponsesByGuestbookId` use case and repository support for retrieving paginated guestbook responses with total count as structured JSON.
- Guestbooks: Added `downloadGuestbookResponsesByCollectionId` and `downloadGuestbookResponsesOfAGuestbook` use cases and repository support for exporting guestbook responses as raw CSV content.
- Guestbooks: Added optional `includeStats` support to `getGuestbooksByCollectionId`, returning `usageCount` and `responseCount` when requested.
Expand Down
26 changes: 25 additions & 1 deletion docs/useCases.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ The different use cases currently available in the package are classified below,
- [Download Guestbook Responses Of A Guestbook](#download-guestbook-responses-of-a-guestbook)
- [Guestbooks write use cases](#guestbooks-write-use-cases)
- [Create a Guestbook](#create-a-guestbook)
- [Edit a Guestbook](#edit-a-guestbook)
- [Set Guestbook Enabled](#set-guestbook-enabled)
- [Assign Dataset Guestbook](#assign-dataset-guestbook)
- [Remove Dataset Guestbook](#remove-dataset-guestbook)
Expand Down Expand Up @@ -3172,6 +3173,7 @@ _See [use case](../src/guestbooks/domain/useCases/GetGuestbook.ts) implementatio

Returns all [Guestbook](../src/guestbooks/domain/models/Guestbook.ts) entries available for a collection.
Set `includeStats` to `true` to include `usageCount` and `responseCount` for each guestbook.
Set `includeInherited` to `true` to include the collection's guestbooks and guestbooks from the collection's hierarchical owners.

##### Example call:

Expand All @@ -3180,9 +3182,10 @@ import { getGuestbooksByCollectionId } from '@iqss/dataverse-client-javascript'

const collectionIdOrAlias = 'root'
const includeStats = true
const includeInherited = true

getGuestbooksByCollectionId
.execute(collectionIdOrAlias, includeStats)
.execute(collectionIdOrAlias, includeStats, includeInherited)
.then((guestbooks: Guestbook[]) => {
/* ... */
})
Expand Down Expand Up @@ -3290,6 +3293,27 @@ createGuestbook.execute(guestbook, collectionIdOrAlias).then(() => {

_See [use case](../src/guestbooks/domain/useCases/CreateGuestbook.ts) implementation_.

#### Edit a Guestbook

Edits an existing guestbook using [EditGuestbookDTO](../src/guestbooks/domain/dtos/EditGuestbookDTO.ts).

##### Example call:

```typescript
import { editGuestbook } from '@iqss/dataverse-client-javascript'

const guestbookId = 123
const guestbook: EditGuestbookDTO = {
name: 'new name'
}

editGuestbook.execute(guestbookId, guestbook).then(() => {
/* ... */
})
```

_See [use case](../src/guestbooks/domain/useCases/EditGuestbook.ts) implementation_.

#### Set Guestbook Enabled

Enables or disables a guestbook in a collection.
Expand Down
29 changes: 29 additions & 0 deletions src/guestbooks/domain/dtos/EditGuestbookDTO.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
export type EditGuestbookQuestionTypeDTO = 'text' | 'textarea' | 'options'

export interface EditGuestbookOptionDTO {
id?: number
value: string
displayOrder: number
}

export interface EditGuestbookCustomQuestionDTO {
id?: number
question: string
required: boolean
displayOrder: number
type: EditGuestbookQuestionTypeDTO
hidden: boolean
optionValues?: EditGuestbookOptionDTO[]
}

export interface EditGuestbookDTO {
id?: number
name: string
enabled: boolean
emailRequired: boolean
nameRequired: boolean
institutionRequired: boolean
positionRequired: boolean
createTime: string
customQuestions?: EditGuestbookCustomQuestionDTO[]
}
2 changes: 2 additions & 0 deletions src/guestbooks/domain/models/Guestbook.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
export type GuestbookQuestionType = 'text' | 'textarea' | 'options'

export interface GuestbookOption {
id?: number
value: string
displayOrder: number
}

export interface GuestbookCustomQuestion {
id?: number
question: string
required: boolean
displayOrder: number
Expand Down
2 changes: 2 additions & 0 deletions src/guestbooks/domain/repositories/IGuestbooksRepository.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { CreateGuestbookDTO } from '../dtos/CreateGuestbookDTO'
import { EditGuestbookDTO } from '../dtos/EditGuestbookDTO'
import { Guestbook } from '../models/Guestbook'
import { GuestbookResponseSubset } from '../models/GuestbookResponse'

Expand All @@ -7,6 +8,7 @@ export interface IGuestbooksRepository {
collectionIdOrAlias: number | string,
guestbook: CreateGuestbookDTO
): Promise<number>
editGuestbook(guestbookId: number, guestbook: EditGuestbookDTO): Promise<void>
getGuestbook(guestbookId: number): Promise<Guestbook>
getGuestbooksByCollectionId(
collectionIdOrAlias: number | string,
Expand Down
17 changes: 17 additions & 0 deletions src/guestbooks/domain/useCases/EditGuestbook.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { EditGuestbookDTO } from '../dtos/EditGuestbookDTO'
import { IGuestbooksRepository } from '../repositories/IGuestbooksRepository'

export class EditGuestbook {
constructor(private readonly guestbooksRepository: IGuestbooksRepository) {}

/**
* Edits an existing guestbook.
*
* @param {number} guestbookId - Guestbook identifier.
* @param {EditGuestbookDTO} guestbook - Guestbook edit payload.
* @returns {Promise<void>}
*/
async execute(guestbookId: number, guestbook: EditGuestbookDTO): Promise<void> {
return await this.guestbooksRepository.editGuestbook(guestbookId, guestbook)
}
}
8 changes: 8 additions & 0 deletions src/guestbooks/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { GuestbooksRepository } from './infra/repositories/GuestbooksRepository'
import { CreateGuestbook } from './domain/useCases/CreateGuestbook'
import { EditGuestbook } from './domain/useCases/EditGuestbook'
import { DownloadGuestbookResponsesByCollectionId } from './domain/useCases/DownloadGuestbookResponsesByCollectionId'
import { DownloadGuestbookResponsesOfAGuestbook } from './domain/useCases/DownloadGuestbookResponsesOfAGuestbook'
import { GetGuestbook } from './domain/useCases/GetGuestbook'
Expand All @@ -12,6 +13,7 @@ import { RemoveDatasetGuestbook } from './domain/useCases/RemoveDatasetGuestbook
const guestbooksRepository = new GuestbooksRepository()

const createGuestbook = new CreateGuestbook(guestbooksRepository)
const editGuestbook = new EditGuestbook(guestbooksRepository)
const downloadGuestbookResponsesByCollectionId = new DownloadGuestbookResponsesByCollectionId(
guestbooksRepository
)
Expand All @@ -29,6 +31,7 @@ const removeDatasetGuestbook = new RemoveDatasetGuestbook(guestbooksRepository)

export {
createGuestbook,
editGuestbook,
downloadGuestbookResponsesByCollectionId,
downloadGuestbookResponsesOfAGuestbook,
getGuestbook,
Expand All @@ -44,6 +47,11 @@ export {
CreateGuestbookCustomQuestionDTO,
CreateGuestbookOptionDTO
} from './domain/dtos/CreateGuestbookDTO'
export {
EditGuestbookDTO,
EditGuestbookCustomQuestionDTO,
EditGuestbookOptionDTO
} from './domain/dtos/EditGuestbookDTO'
export {
GuestbookResponsesDTO,
GuestbookResponsesPaginationDTO
Expand Down
12 changes: 12 additions & 0 deletions src/guestbooks/infra/repositories/GuestbooksRepository.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ApiRepository } from '../../../core/infra/repositories/ApiRepository'
import { CreateGuestbookDTO } from '../../domain/dtos/CreateGuestbookDTO'
import { EditGuestbookDTO } from '../../domain/dtos/EditGuestbookDTO'
import { GuestbookResponsesDTO } from '../../domain/dtos/GuestbookResponsesDTO'
import { Guestbook } from '../../domain/models/Guestbook'
import { GuestbookResponseSubset } from '../../domain/models/GuestbookResponse'
Expand All @@ -24,6 +25,17 @@ export class GuestbooksRepository extends ApiRepository implements IGuestbooksRe
})
}

public async editGuestbook(guestbookId: number, guestbook: EditGuestbookDTO): Promise<void> {
return this.doPut(
this.buildApiEndpoint(this.guestbooksResourceName, undefined, guestbookId),
guestbook
)
.then(() => undefined)
.catch((error) => {
throw error
})
}

public async getGuestbook(guestbookId: number): Promise<Guestbook> {
return this.doGet(
this.buildApiEndpoint(this.guestbooksResourceName, undefined, guestbookId),
Expand Down
Loading
Loading