-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added observations & fixed clip timing.
- Loading branch information
1 parent
a467c12
commit a00a075
Showing
40 changed files
with
860 additions
and
212 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,29 @@ | ||
import { z } from 'zod'; | ||
import { suggestIdentification } from '../services/identifications/identifications.js'; | ||
import { getTaxaFromPartialSearch } from '../services/inat/index.js'; | ||
import { recordAchievement } from '../services/points/achievement.js'; | ||
import { procedure, router } from '../trpc/trpc'; | ||
import { useUser } from '../utils/env/env.js'; | ||
|
||
export default router({ | ||
vote: procedure | ||
.input( | ||
z.object({ | ||
id: z.string(), | ||
id: z.number(), | ||
vote: z.enum(['up', 'down']), | ||
comment: z.string().optional() | ||
}) | ||
) | ||
.mutation(async ({ input, ctx }) => { | ||
const points = await recordAchievement('vote', ctx.user); | ||
ctx.points(points); | ||
}) | ||
const user = useUser(); | ||
const points = await recordAchievement('vote', user.id); | ||
if (points) ctx.points(points); | ||
}), | ||
searchForTaxa: procedure.input(z.object({ query: z.string() })).query(async ({ input }) => { | ||
return await getTaxaFromPartialSearch(input.query); | ||
}), | ||
|
||
suggest: procedure.input(z.object({ observationId: z.number(), iNatId: z.number() })).mutation(async ({ input }) => { | ||
return await suggestIdentification(input.observationId, input.iNatId); | ||
}) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,42 @@ | ||
import { z } from 'zod'; | ||
import { createObservationsFromCapture, ObservationPayload } from '../services/observations/observations.js'; | ||
import { editorProcedure, router } from '../trpc/trpc.js'; | ||
import { | ||
createObservationsFromCapture, | ||
getObservationCount, | ||
getObservations, | ||
ObservationPayload | ||
} from '../services/observations/observations.js'; | ||
import { editorProcedure, procedure, router } from '../trpc/trpc.js'; | ||
|
||
export const Pagination = z.object({ | ||
page: z.number().default(1), | ||
size: z.number().default(30) | ||
}); | ||
|
||
export type Pagination = z.infer<typeof Pagination>; | ||
|
||
export const Query = z.object({ | ||
start: z.coerce.date().optional(), | ||
end: z.coerce.date().optional() | ||
}); | ||
|
||
export type Query = z.infer<typeof Query>; | ||
|
||
export default router({ | ||
createObservationsFromCapture: editorProcedure | ||
.input(z.object({ captureId: z.number(), observations: z.array(ObservationPayload) })) | ||
.mutation(async ({ input }) => { | ||
return await createObservationsFromCapture(input.captureId, input.observations); | ||
}) | ||
}), | ||
|
||
list: procedure.input(z.object({ meta: Pagination, query: Query.optional() })).query(async ({ input }) => { | ||
const count = await getObservationCount(); | ||
const data = await getObservations(input.meta); | ||
return { | ||
meta: { | ||
...input.meta, | ||
total: count | ||
}, | ||
data | ||
}; | ||
}) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { identifications } from '../../db/schema/index.js'; | ||
import { useDB } from '../../db/transaction.js'; | ||
import { useUser } from '../../utils/env/env.js'; | ||
import { getTaxaInfo } from '../inat/index.js'; | ||
|
||
export const suggestIdentification = async (observationId: number, iNatId: number) => { | ||
const source = await getTaxaInfo(iNatId); | ||
return createIdentification(observationId, iNatId, source.preferred_common_name ?? source.name); | ||
}; | ||
|
||
export const createIdentification = async (observationId: number, iNatId: number, name: string) => { | ||
const db = useDB(); | ||
const user = useUser(); | ||
|
||
const [identification] = await db | ||
.insert(identifications) | ||
.values({ | ||
name, | ||
nickname: name, | ||
sourceId: iNatId.toString(), | ||
observationId, | ||
suggestedBy: user.id | ||
}) | ||
.returning(); | ||
|
||
return identification; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.