Skip to content

Commit

Permalink
fix: use juggling null checks instead of strict
Browse files Browse the repository at this point in the history
  • Loading branch information
Silthus committed Feb 15, 2024
1 parent a10a048 commit 520265f
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/db/edit/streamListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export async function testStreamListener (callback?: (change: ChangeStreamDocume
// eslint-disable-next-line @typescript-eslint/no-misused-promises
return (await createChangeStream()).on('change', async (change: ChangeStreamDocument) => {
await onChange(change)
if (callback !== undefined) callback(change)
if (callback != null) callback(change)
})
}

Expand Down
4 changes: 2 additions & 2 deletions src/graphql/organization/OrganizationQueries.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import type OrganizationDataSource from '../../model/OrganizationDataSource'
import { QueryByIdType, OrganizationGQLFilter, Sort, Context } from '../../types'
import { Context, OrganizationGQLFilter, QueryByIdType, Sort } from '../../types'

const OrganizationQueries = {
organization: async (_: any,
{ muuid }: QueryByIdType,
context: Context, info) => {
const { dataSources } = context
const { organizations }: { organizations: OrganizationDataSource } = dataSources
if (muuid !== undefined) {
if (muuid != null) {
return await organizations.findOneOrganizationByOrgId(muuid)
}
return null
Expand Down
10 changes: 5 additions & 5 deletions src/graphql/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ import { gql } from 'apollo-server-express'
import { DocumentNode } from 'graphql'

import { CommonResolvers, CommonTypeDef } from './common/index.js'
import { HistoryQueries, HistoryFieldResolvers } from '../graphql/history/index.js'
import { QueryByIdType, GQLFilter, Sort, Context } from '../types'
import { HistoryFieldResolvers, HistoryQueries } from '../graphql/history/index.js'
import { Context, GQLFilter, QueryByIdType, Sort } from '../types'
import { AreaType, CountByDisciplineType } from '../db/AreaTypes.js'
import { ClimbGQLQueryType, ClimbType } from '../db/ClimbTypes.js'
import AreaDataSource from '../model/AreaDataSource.js'
import { MediaMutations, MediaQueries, MediaResolvers } from './media/index.js'
import { PostMutations, PostQueries, PostResolvers } from './posts/index.js'
import { XMediaMutations, XMediaQueries, XMediaResolvers } from './xmedia/index.js'
import { AreaQueries, AreaMutations } from './area/index.js'
import { AreaMutations, AreaQueries } from './area/index.js'
import { ClimbMutations } from './climb/index.js'
import { OrganizationMutations, OrganizationQueries } from './organization/index.js'
import { TickMutations, TickQueries } from './tick/index.js'
import { UserQueries, UserMutations, UserResolvers } from './user/index.js'
import { UserMutations, UserQueries, UserResolvers } from './user/index.js'
import { getAuthorMetadataFromBaseNode } from '../db/utils/index.js'
import { geojsonPointToLatitude, geojsonPointToLongitude } from '../utils/helpers.js'

Expand Down Expand Up @@ -74,7 +74,7 @@ const resolvers = {
{ uuid }: QueryByIdType,
{ dataSources }: Context) => {
const { areas } = dataSources
if (uuid !== undefined && uuid !== '') {
if (uuid != null && uuid !== '') {
return await areas.findOneClimbByUUID(muid.from(uuid))
}
return null
Expand Down
8 changes: 4 additions & 4 deletions src/model/BulkImportDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export default class BulkImportDataSource extends MutableAreaDataSource {
addedOrUpdatedClimbs: []
}
let area: AreaType | null
if (areaNode.uuid !== undefined && areaNode.uuid !== null) {
if (areaNode.uuid != null) {
area = await this.updateAreaWith({
user,
areaUuid: muuid.from(areaNode.uuid),
Expand All @@ -88,7 +88,7 @@ export default class BulkImportDataSource extends MutableAreaDataSource {
} else {
throw new Error(`area with id ${areaNode.uuid.toUUID().toString()} (${areaNode.areaName ?? 'unknown name'}) not found`)
}
} else if (areaNode.areaName !== undefined) {
} else if (areaNode.areaName != null) {
area = await this.addAreaWith({
user,
areaName: areaNode.areaName,
Expand All @@ -111,15 +111,15 @@ export default class BulkImportDataSource extends MutableAreaDataSource {
} else {
throw new Error('areaName or id is required')
}
if (areaNode.children !== undefined) {
if (areaNode.children != null) {
for (const child of areaNode.children) {
const childResult = await addOrUpdateArea(child, area.metadata.area_id)
result.updatedAreas.push(...childResult.updatedAreas)
result.addedAreas.push(...childResult.addedAreas)
result.addedOrUpdatedClimbs.push(...childResult.addedOrUpdatedClimbs)
}
}
if (areaNode.climbs !== undefined) {
if (areaNode.climbs != null) {
const addedOrUpdatedClimbs = await Promise.all(await climbs?.addOrUpdateClimbsWith({
userId: user,
parentId: area.metadata.area_id,
Expand Down
2 changes: 1 addition & 1 deletion src/model/MutableAreaDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { createInstance as createExperimentalUserDataSource } from '../model/Exp
import { sanitizeStrict } from '../utils/sanitize.js'
import AreaDataSource from './AreaDataSource.js'
import { changelogDataSource } from './ChangeLogDataSource.js'
import { withTransaction } from '../utils/helpers'
import { withTransaction } from '../utils/helpers.js'

isoCountries.registerLocale(enJson)

Expand Down
2 changes: 1 addition & 1 deletion src/model/MutableClimbDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { changelogDataSource } from './ChangeLogDataSource.js'
import ClimbDataSource from './ClimbDataSource.js'
import { createInstance as createExperimentalUserDataSource } from './ExperimentalUserDataSource.js'
import MutableAreaDataSource from './MutableAreaDataSource.js'
import { withTransaction } from '../utils/helpers'
import { withTransaction } from '../utils/helpers.js'

export interface AddOrUpdateClimbsOptions {
userId: MUUID
Expand Down
2 changes: 1 addition & 1 deletion src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import type { DataSources } from 'apollo-server-core/dist/graphqlOptions'
import UserDataSource from './model/UserDataSource.js'
import express from 'express'
import * as http from 'http'
import BulkImportDataSource from './model/BulkImportDataSource'
import BulkImportDataSource from './model/BulkImportDataSource.js'

export async function createServer (): Promise<{ app: express.Application, server: ApolloServer }> {
const schema = applyMiddleware(
Expand Down

0 comments on commit 520265f

Please sign in to comment.