Skip to content

Commit

Permalink
Merge branch 'main' into feature/web-parent-subpage-organization-layout
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] authored Dec 5, 2024
2 parents 7a0ae41 + 4704971 commit e4723cd
Show file tree
Hide file tree
Showing 20 changed files with 378 additions and 81 deletions.
37 changes: 4 additions & 33 deletions apps/native/app/src/graphql/fragments/vehicle.fragment.graphql
Original file line number Diff line number Diff line change
@@ -1,39 +1,10 @@
fragment VehicleFragment on VehiclesVehicle {
isCurrent
fragment VehicleFragment on VehicleListed {
permno
regno
vin
type
color
firstRegDate
make
colorName
modelYear
productYear
registrationType
role
operatorStartDate
operatorEndDate
outOfUse
otherOwners
termination
buyerPersidno
ownerPersidno
vehicleStatus
useGroup
vehGroup
plateStatus
nextInspection {
nextInspectionDate
nextInspectionDateIfPassedInspectionToday
}
operatorNumber
primaryOperator
ownerSsid
ownerName
lastInspectionResult
lastInspectionDate
lastInspectionType
nextInspectionDate
nextAvailableMileageReadDate
requiresMileageRegistration
canRegisterMileage
nextMainInspection
}
4 changes: 2 additions & 2 deletions apps/native/app/src/graphql/queries/vehicles.graphql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
query ListVehicles($input: GetVehiclesForUserInput!) {
vehiclesList(input: $input) {
query ListVehiclesV2($input: GetVehiclesListV2Input!) {
vehiclesListV2(input: $input) {
vehicleList {
...VehicleFragment
}
Expand Down
6 changes: 2 additions & 4 deletions apps/native/app/src/screens/home/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ import {
} from './licenses-module'
import { OnboardingModule } from './onboarding-module'
import {
useListVehiclesQuery,
useListVehiclesV2Query,
validateVehiclesInitialData,
VehiclesModule,
} from './vehicles-module'
Expand Down Expand Up @@ -174,13 +174,11 @@ export const MainHomeScreen: NavigationFunctionComponent = ({
skip: !airDiscountWidgetEnabled,
})

const vehiclesRes = useListVehiclesQuery({
const vehiclesRes = useListVehiclesV2Query({
variables: {
input: {
page: 1,
pageSize: 15,
showDeregeristered: false,
showHistory: false,
},
},
skip: !vehiclesWidgetEnabled,
Expand Down
14 changes: 7 additions & 7 deletions apps/native/app/src/screens/home/vehicles-module.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import illustrationSrc from '../../assets/illustrations/le-moving-s4.png'
import { navigateTo } from '../../lib/deep-linking'
import { VehicleItem } from '../vehicles/components/vehicle-item'
import {
ListVehiclesQuery,
useListVehiclesQuery,
ListVehiclesV2Query,
useListVehiclesV2Query,
} from '../../graphql/types/schema'
import { screenWidth } from '../../utils/dimensions'

Expand All @@ -30,15 +30,15 @@ const validateVehiclesInitialData = ({
data,
loading,
}: {
data: ListVehiclesQuery | undefined
data: ListVehiclesV2Query | undefined
loading: boolean
}) => {
if (loading) {
return true
}
// Only show widget initially if there are vehicles that require mileage registration
if (
data?.vehiclesList?.vehicleList?.some(
data?.vehiclesListV2?.vehicleList?.some(
(vehicle) => vehicle.requiresMileageRegistration,
)
) {
Expand All @@ -49,7 +49,7 @@ const validateVehiclesInitialData = ({
}

interface VehiclesModuleProps {
data: ListVehiclesQuery | undefined
data: ListVehiclesV2Query | undefined
loading: boolean
error?: ApolloError | undefined
}
Expand All @@ -59,7 +59,7 @@ const VehiclesModule = React.memo(
const theme = useTheme()
const intl = useIntl()

const vehicles = data?.vehiclesList?.vehicleList
const vehicles = data?.vehiclesListV2?.vehicleList

// Reorder vehicles so vehicles that require mileage registration are shown first
const reorderedVehicles = useMemo(
Expand Down Expand Up @@ -170,4 +170,4 @@ const VehiclesModule = React.memo(
},
)

export { VehiclesModule, validateVehiclesInitialData, useListVehiclesQuery }
export { VehiclesModule, validateVehiclesInitialData, useListVehiclesV2Query }
14 changes: 7 additions & 7 deletions apps/native/app/src/screens/vehicles/components/vehicle-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import React from 'react'
import { FormattedDate, FormattedMessage } from 'react-intl'
import { SafeAreaView, TouchableHighlight, View, ViewStyle } from 'react-native'
import styled, { useTheme } from 'styled-components/native'
import { ListVehiclesQuery } from '../../../graphql/types/schema'
import { ListVehiclesV2Query } from '../../../graphql/types/schema'
import { navigateTo } from '../../../lib/deep-linking'

function differenceInMonths(a: Date, b: Date) {
return a.getMonth() - b.getMonth() + 12 * (a.getFullYear() - b.getFullYear())
}

type VehicleListItem = NonNullable<
NonNullable<ListVehiclesQuery['vehiclesList']>['vehicleList']
NonNullable<ListVehiclesV2Query['vehiclesListV2']>['vehicleList']
>[0]

const Cell = styled(TouchableHighlight)`
Expand All @@ -31,8 +31,8 @@ export const VehicleItem = React.memo(
style?: ViewStyle
}) => {
const theme = useTheme()
const nextInspection = item?.nextInspection?.nextInspectionDate
? new Date(item?.nextInspection.nextInspectionDate)
const nextInspection = item?.nextMainInspection
? new Date(item?.nextMainInspection)
: null

const isInspectionDeadline =
Expand All @@ -51,14 +51,14 @@ export const VehicleItem = React.memo(
onPress={() => {
navigateTo(`/vehicle/`, {
id: item.permno,
title: item.type,
title: item.make,
})
}}
>
<SafeAreaView>
<VehicleCard
title={item.type}
color={item.color}
title={item.make}
color={item.colorName}
number={item.regno}
minHeight={minHeight}
label={
Expand Down
28 changes: 14 additions & 14 deletions apps/native/app/src/screens/vehicles/vehicles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import { useTheme } from 'styled-components/native'
import illustrationSrc from '../../assets/illustrations/le-moving-s4.png'
import { BottomTabsIndicator } from '../../components/bottom-tabs-indicator/bottom-tabs-indicator'
import {
ListVehiclesQuery,
useListVehiclesQuery,
ListVehiclesV2Query,
useListVehiclesV2Query,
} from '../../graphql/types/schema'
import { createNavigationOptionHooks } from '../../hooks/create-navigation-option-hooks'
import { useConnectivityIndicator } from '../../hooks/use-connectivity-indicator'
Expand All @@ -32,7 +32,7 @@ const { useNavigationOptions, getNavigationOptions } =
}))

type VehicleListItem = NonNullable<
NonNullable<ListVehiclesQuery['vehiclesList']>['vehicleList']
NonNullable<ListVehiclesV2Query['vehiclesListV2']>['vehicleList']
>[0]

type ListItem =
Expand Down Expand Up @@ -61,8 +61,6 @@ const Empty = () => (
const input = {
page: 1,
pageSize: 10,
showDeregeristered: false,
showHistory: false,
}

export const VehiclesScreen: NavigationFunctionComponent = ({
Expand All @@ -77,7 +75,7 @@ export const VehiclesScreen: NavigationFunctionComponent = ({
const scrollY = useRef(new Animated.Value(0)).current
const loadingTimeout = useRef<ReturnType<typeof setTimeout>>()

const res = useListVehiclesQuery({
const res = useListVehiclesV2Query({
variables: {
input,
},
Expand Down Expand Up @@ -135,7 +133,9 @@ export const VehiclesScreen: NavigationFunctionComponent = ({
// Extract key of data
const keyExtractor = useCallback(
(item: ListItem, index: number) =>
item.__typename === 'Skeleton' ? String(item.id) : `${item.vin}${index}`,
item.__typename === 'Skeleton'
? String(item.id)
: `${item.permno}${index}`,
[],
)

Expand All @@ -147,7 +147,7 @@ export const VehiclesScreen: NavigationFunctionComponent = ({
__typename: 'Skeleton',
}))
}
return res?.data?.vehiclesList?.vehicleList || []
return res?.data?.vehiclesListV2?.vehicleList || []
}, [res.data, res.loading])

return (
Expand Down Expand Up @@ -184,8 +184,8 @@ export const VehiclesScreen: NavigationFunctionComponent = ({
if (res.loading) {
return
}
const pageNumber = res.data?.vehiclesList?.paging?.pageNumber ?? 1
const totalPages = res.data?.vehiclesList?.paging?.totalPages ?? 1
const pageNumber = res.data?.vehiclesListV2?.paging?.pageNumber ?? 1
const totalPages = res.data?.vehiclesListV2?.paging?.totalPages ?? 1
if (pageNumber >= totalPages) {
return
}
Expand All @@ -200,11 +200,11 @@ export const VehiclesScreen: NavigationFunctionComponent = ({
},
updateQuery(prev, { fetchMoreResult }) {
return {
vehiclesList: {
...fetchMoreResult.vehiclesList,
vehiclesListV2: {
...fetchMoreResult.vehiclesListV2,
vehicleList: [
...(prev.vehiclesList?.vehicleList ?? []),
...(fetchMoreResult.vehiclesList?.vehicleList ?? []),
...(prev.vehiclesListV2?.vehicleList ?? []),
...(fetchMoreResult.vehiclesListV2?.vehicleList ?? []),
],
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class MeNotificationsController {
@CurrentUser() user: User,
@Query() query: ExtendedPaginationDto,
): Promise<PaginatedNotificationDto> {
return this.notificationService.findMany(user, query)
return this.notificationService.findManyWithTemplate(user.nationalId, query)
}

@Get('/unread-count')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ import {
Body,
Controller,
Get,
Headers,
HttpStatus,
Inject,
Param,
Post,
Query,
UseGuards,
Version,
} from '@nestjs/common'
import { ApiTags } from '@nestjs/swagger'
Expand All @@ -19,6 +22,12 @@ import { CreateHnippNotificationDto } from './dto/createHnippNotification.dto'
import { HnippTemplate } from './dto/hnippTemplate.response'
import { NotificationsService } from './notifications.service'
import type { Locale } from '@island.is/shared/types'
import {
ExtendedPaginationDto,
PaginatedNotificationDto,
} from './dto/notification.dto'
import { IdsUserGuard, Scopes, ScopesGuard } from '@island.is/auth-nest-tools'
import { AdminPortalScope } from '@island.is/auth/scopes'

@Controller('notifications')
@ApiTags('notifications')
Expand Down Expand Up @@ -85,6 +94,20 @@ export class NotificationsController {
return await this.notificationsService.getTemplate(templateId, locale)
}

@UseGuards(IdsUserGuard, ScopesGuard)
@Scopes(AdminPortalScope.serviceDesk)
@Get('/')
@Documentation({
summary: 'Returns a paginated list of notifications for a national id',
response: { status: HttpStatus.OK, type: PaginatedNotificationDto },
})
findMany(
@Headers('X-Query-National-Id') nationalId: string,
@Query() query: ExtendedPaginationDto,
): Promise<PaginatedNotificationDto> {
return this.notificationsService.findMany(nationalId, query)
}

@Documentation({
summary: 'Creates a new notification and adds to queue',
includeNoContentResponse: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,24 @@ export class NotificationsService {
)
}

async findMany(
user: User,
findMany(
nationalId: string,
query: ExtendedPaginationDto,
): Promise<PaginatedNotificationDto> {
return paginate({
Model: this.notificationModel,
limit: query.limit || 10,
after: query.after || '',
before: query.before,
primaryKeyField: 'id',
orderOption: [['id', 'DESC']],
where: { recipient: nationalId },
attributes: ['id', 'messageId', 'senderId', 'created', 'updated'],
})
}

async findManyWithTemplate(
nationalId: string,
query: ExtendedPaginationDto,
): Promise<PaginatedNotificationDto> {
const locale = mapToLocale(query.locale as Locale)
Expand All @@ -273,7 +289,7 @@ export class NotificationsService {
before: query.before,
primaryKeyField: 'id',
orderOption: [['id', 'DESC']],
where: { recipient: user.nationalId },
where: { recipient: nationalId },
})

const formattedNotifications = await Promise.all(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,9 @@ describe('NotificationsService', () => {
.spyOn(service, 'findMany')
.mockImplementation(async () => mockedResponse)

expect(await service.findMany(user, query)).toBe(mockedResponse)
expect(await service.findMany(user.nationalId, query)).toBe(
mockedResponse,
)
})
})

Expand Down
20 changes: 20 additions & 0 deletions libs/api/domains/notifications/src/lib/notifications.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,21 @@ export class Notification {
message!: NotificationMessage
}

@ObjectType()
export class AdminNotification {
@Field(() => Int)
id!: number

@Field(() => ID)
notificationId!: string

@Field(() => NotificationSender)
sender!: NotificationSender

@Field(() => GraphQLISODateTime)
sent!: Date
}

@InputType()
export class NotificationsInput extends PaginationInput() {}

Expand All @@ -101,6 +116,11 @@ export class NotificationsResponse extends PaginatedResponse(Notification) {
unseenCount?: number
}

@ObjectType('AdminNotifications')
export class AdminNotificationsResponse extends PaginatedResponse(
AdminNotification,
) {}

@ObjectType()
export class NotificationResponse {
@Field(() => Notification)
Expand Down
Loading

0 comments on commit e4723cd

Please sign in to comment.