Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add getBeds query to api services #1147

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
23 changes: 22 additions & 1 deletion api-services/mutations/tasks/bed_mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
import {
CreateBedRequest,
DeleteBedRequest,
GetBedRequest,
GetBedRequest, GetBedsRequest,
UpdateBedRequest
} from '@helpwave/proto-ts/services/tasks_svc/v1/bed_svc_pb'
import { QueryKeys } from '../query_keys'
Expand Down Expand Up @@ -33,6 +33,27 @@ export const useBedQuery = (bedId: string | undefined) => {
})
}

export const useBedsQuery = (roomId?: string) => {
return useQuery({
queryKey: [QueryKeys.beds, roomId ?? 'all'],
queryFn: async () => {
const req = new GetBedsRequest()
if (roomId) {
req.setRoomId(roomId)
}
const res = await APIServices.bed.getBeds(req, getAuthenticatedGrpcMetadata())

const beds: BedWithRoomId[] = res.getBedsList().map(bed => ({
id: bed.getId(),
name: bed.getName(),
roomId: bed.getRoomId()
}))

return beds
},
})
}

export const useBedCreateMutation = () => {
const queryClient = useQueryClient()
return useMutation({
Expand Down
3 changes: 3 additions & 0 deletions api-services/offline/tasks/bed_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ export class BedOfflineServicePromiseClient extends BedServicePromiseClient {
.setBedsList(list)
}

/**
* @deprecated The method should not be used anymore, use getBeds with the roomId as a parameter instead
*/
async getBedsByRoom(request: GetBedsByRoomRequest, _?: Metadata): Promise<GetBedsByRoomResponse> {
const beds = BedOfflineService.findMany(request.getRoomId())

Expand Down
Loading