diff --git a/site/gatsby-site/server/fields/common.ts b/site/gatsby-site/server/fields/common.ts index ec5f70bfc5..a92b38dc09 100644 --- a/site/gatsby-site/server/fields/common.ts +++ b/site/gatsby-site/server/fields/common.ts @@ -212,6 +212,7 @@ export const createNotificationsOnNewIncident = async (fullDocument: DBIncident, type: 'new-incidents', incident_id: incidentId, processed: false, + created_at: new Date(), }); const entityFields: (keyof DBIncident)[] = [ @@ -239,6 +240,7 @@ export const createNotificationsOnNewIncident = async (fullDocument: DBIncident, incident_id: incidentId, entity_id: entityId, processed: false, + created_at: new Date(), }); } } @@ -363,6 +365,7 @@ export const logReportHistory = async (updated: DBReport, context: Context) => { const reportHistory: DBReportHistory = { ...updated, modifiedBy: context.user?.id ?? '', + created_at: new Date(), _id: undefined, } @@ -376,6 +379,7 @@ export const logIncidentHistory = async (updated: DBIncident, context: Context) const incidentHistory: DBIncidentHistory = { ...updated, modifiedBy: context.user?.id ?? '', + created_at: new Date(), _id: undefined, } diff --git a/site/gatsby-site/server/fields/reports.ts b/site/gatsby-site/server/fields/reports.ts index 1d97b4376c..355f553c5f 100644 --- a/site/gatsby-site/server/fields/reports.ts +++ b/site/gatsby-site/server/fields/reports.ts @@ -4,6 +4,7 @@ import { generateMutationFields, generateQueryFields, getQueryResolver } from ". import { isRole } from "../rules"; import { linkReportsToIncidents, logReportHistory } from "./common"; import { ReportType } from "../types/report"; +import { Context, DBReport } from "../interfaces"; export const queryFields: GraphQLFieldConfigMap = { @@ -185,10 +186,10 @@ export const mutationFields: GraphQLFieldConfigMap = { type: new GraphQLNonNull(CreateVariantInput), }, }, - resolve: async (source, { input }, context) => { + resolve: async (source, { input }, context: Context) => { const incidents = context.client.db('aiidprod').collection("incidents"); - const reports = context.client.db('aiidprod').collection("reports"); + const reports = context.client.db('aiidprod').collection("reports"); const parentIncident = await incidents.findOne({ incident_id: input.incidentId }); @@ -196,7 +197,9 @@ export const mutationFields: GraphQLFieldConfigMap = { throw `Incident ${input.incidentId} not found`; } - const report_number = (await reports.find({}).sort({ report_number: -1 }).limit(1).next()).report_number + 1; + const lastReport = await reports.find({}).sort({ report_number: -1 }).limit(1).next(); + + const report_number = lastReport ? lastReport.report_number + 1 : 1; const now = new Date(); @@ -225,9 +228,10 @@ export const mutationFields: GraphQLFieldConfigMap = { language: 'en', tags: ['variant:unreviewed'], inputs_outputs: input.variant.inputs_outputs, + user: context.user?.id ?? '', }; - await reports.insertOne({ ...newReport, report_number: newReport.report_number }); + await reports.insertOne({ ...newReport, report_number: newReport.report_number, created_at: new Date() }); const incident_ids = [input.incidentId]; const report_numbers = [newReport.report_number]; diff --git a/site/gatsby-site/server/fields/submissions.ts b/site/gatsby-site/server/fields/submissions.ts index bc441fadad..e3d0a83e10 100644 --- a/site/gatsby-site/server/fields/submissions.ts +++ b/site/gatsby-site/server/fields/submissions.ts @@ -8,7 +8,7 @@ import { GraphQLInputObjectType } from 'graphql'; import { generateMutationFields, generateQueryFields } from '../utils'; -import { Context, DBIncident, DBSubmission } from '../interfaces'; +import { Context, DBIncident, DBNotification, DBSubmission } from '../interfaces'; import { allow } from 'graphql-shield'; import { ObjectIdScalar } from '../scalars'; import { isRole } from '../rules'; @@ -62,7 +62,7 @@ export const mutationFields: GraphQLFieldConfigMap = { // TODO: Strictly type these collections using the DB* types const reports = context.client.db('aiidprod').collection("reports"); - const notificationsCollection = context.client.db('customData').collection("notifications"); + const notificationsCollection = context.client.db('customData').collection("notifications"); const incidentsHistory = context.client.db('history').collection("incidents"); const reportsHistory = context.client.db('history').collection("reports"); @@ -116,11 +116,11 @@ export const mutationFields: GraphQLFieldConfigMap = { from_reports: [report_number] } } - if(submission.epoch_date_modified) { + if (submission.epoch_date_modified) { newIncident.epoch_date_modified = submission.epoch_date_modified; } - await incidents.insertOne({ ...newIncident, incident_id: newIncident.incident_id }); + await incidents.insertOne({ ...newIncident, incident_id: newIncident.incident_id, created_at: new Date() }); await createNotificationsOnNewIncident(newIncident, context); @@ -132,7 +132,8 @@ export const mutationFields: GraphQLFieldConfigMap = { type: 'submission-promoted', incident_id: newIncident.incident_id, processed: false, - userId: submission.user + userId: submission.user, + created_at: new Date(), }); } @@ -140,6 +141,7 @@ export const mutationFields: GraphQLFieldConfigMap = { ...newIncident, reports: [report_number], incident_id: newIncident.incident_id, + created_at: new Date(), }; if (submission.user) { @@ -205,6 +207,7 @@ export const mutationFields: GraphQLFieldConfigMap = { ...incidentValues, reports: [...incidentValues.reports!, report_number], embedding, + created_at: new Date(), } if (submission.user) { @@ -246,11 +249,11 @@ export const mutationFields: GraphQLFieldConfigMap = { newReport.user = submission.user; } - if(submission.epoch_date_modified) { + if (submission.epoch_date_modified) { newReport.epoch_date_modified = submission.epoch_date_modified; } - await reports.insertOne({ ...newReport, report_number: newReport.report_number }); + await reports.insertOne({ ...newReport, report_number: newReport.report_number, created_at: new Date() }); const incident_ids: number[] = parentIncidents.map(incident => incident.incident_id!); const report_numbers: number[] = [newReport.report_number]; diff --git a/site/gatsby-site/server/generated/graphql.ts b/site/gatsby-site/server/generated/graphql.ts index a7d4479751..4be1188f68 100644 --- a/site/gatsby-site/server/generated/graphql.ts +++ b/site/gatsby-site/server/generated/graphql.ts @@ -1139,6 +1139,7 @@ export type History_Incident = { AllegedDeveloperOfAISystem?: Maybe>>; AllegedHarmedOrNearlyHarmedParties?: Maybe>>; _id?: Maybe; + created_at?: Maybe; date: Scalars['String']['output']; description?: Maybe; editor_dissimilar_incidents?: Maybe>>; @@ -1193,6 +1194,7 @@ export type History_IncidentFilterType = { NOR?: InputMaybe>>; OR?: InputMaybe>>; _id?: InputMaybe; + created_at?: InputMaybe; date?: InputMaybe; description?: InputMaybe; editor_dissimilar_incidents?: InputMaybe; @@ -1275,6 +1277,7 @@ export enum History_IncidentSortByInput { export type History_IncidentSortType = { _id?: InputMaybe; + created_at?: InputMaybe; date?: InputMaybe; description?: InputMaybe; editor_notes?: InputMaybe; @@ -1334,6 +1337,7 @@ export type History_Report = { _id?: Maybe; authors?: Maybe>>; cloudinary_id?: Maybe; + created_at?: Maybe; date_downloaded: Scalars['DateTime']['output']; date_modified: Scalars['DateTime']['output']; date_published: Scalars['DateTime']['output']; @@ -1406,6 +1410,7 @@ export type History_ReportFilterType = { _id?: InputMaybe; authors?: InputMaybe; cloudinary_id?: InputMaybe; + created_at?: InputMaybe; date_downloaded?: InputMaybe; date_modified?: InputMaybe; date_published?: InputMaybe; @@ -1485,6 +1490,7 @@ export enum History_ReportSortByInput { export type History_ReportSortType = { _id?: InputMaybe; cloudinary_id?: InputMaybe; + created_at?: InputMaybe; date_downloaded?: InputMaybe; date_modified?: InputMaybe; date_published?: InputMaybe; @@ -2562,6 +2568,7 @@ export type MutationUpsertOneSubscriptionArgs = { export type Notification = { __typename?: 'Notification'; _id?: Maybe; + created_at?: Maybe; entity_id?: Maybe; incident_id?: Maybe; isUpdate?: Maybe; @@ -2577,6 +2584,7 @@ export type NotificationFilterType = { NOR?: InputMaybe>>; OR?: InputMaybe>>; _id?: InputMaybe; + created_at?: InputMaybe; entity_id?: InputMaybe; incident_id?: InputMaybe; isUpdate?: InputMaybe; @@ -2657,6 +2665,7 @@ export enum NotificationSortByInput { export type NotificationSortType = { _id?: InputMaybe; + created_at?: InputMaybe; entity_id?: InputMaybe; incident_id?: InputMaybe; isUpdate?: InputMaybe; @@ -3090,6 +3099,7 @@ export type Report = { _id?: Maybe; authors: Array>; cloudinary_id: Scalars['String']['output']; + created_at?: Maybe; date_downloaded: Scalars['DateTime']['output']; date_modified: Scalars['DateTime']['output']; date_published: Scalars['DateTime']['output']; @@ -3189,6 +3199,7 @@ export type ReportFilterType = { _id?: InputMaybe; authors?: InputMaybe; cloudinary_id?: InputMaybe; + created_at?: InputMaybe; date_downloaded?: InputMaybe; date_modified?: InputMaybe; date_published?: InputMaybe; @@ -3221,6 +3232,7 @@ export type ReportInsertType = { _id?: InputMaybe; authors: Array>; cloudinary_id: Scalars['String']['input']; + created_at?: InputMaybe; date_downloaded: Scalars['DateTime']['input']; date_modified: Scalars['DateTime']['input']; date_published: Scalars['DateTime']['input']; @@ -3253,6 +3265,7 @@ export type ReportSetType = { _id?: InputMaybe; authors?: InputMaybe>>; cloudinary_id?: InputMaybe; + created_at?: InputMaybe; date_downloaded?: InputMaybe; date_modified?: InputMaybe; date_published?: InputMaybe; @@ -3329,6 +3342,7 @@ export enum ReportSortByInput { export type ReportSortType = { _id?: InputMaybe; cloudinary_id?: InputMaybe; + created_at?: InputMaybe; date_downloaded?: InputMaybe; date_modified?: InputMaybe; date_published?: InputMaybe; diff --git a/site/gatsby-site/server/types/incidentHistory.ts b/site/gatsby-site/server/types/incidentHistory.ts index 77ca3c2ff2..85fbefaf7f 100644 --- a/site/gatsby-site/server/types/incidentHistory.ts +++ b/site/gatsby-site/server/types/incidentHistory.ts @@ -1,6 +1,7 @@ import { GraphQLInt, GraphQLList, GraphQLNonNull, GraphQLObjectType, GraphQLString } from "graphql"; import { ObjectIdScalar } from "../scalars"; import { IncidentEmbeddingType, NlpSimilarIncidentType, TsneType } from "./types"; +import { GraphQLDateTime } from "graphql-scalars"; export const IncidentHistoryType = new GraphQLObjectType({ name: 'History_incident', @@ -9,6 +10,7 @@ export const IncidentHistoryType = new GraphQLObjectType({ AllegedDeployerOfAISystem: { type: new GraphQLList(GraphQLString), resolve: (source) => source['Alleged deployer of AI system'] }, AllegedDeveloperOfAISystem: { type: new GraphQLList(GraphQLString), resolve: (source) => source['Alleged developer of AI system'] }, AllegedHarmedOrNearlyHarmedParties: { type: new GraphQLList(GraphQLString), resolve: (source) => source['Alleged harmed or nearly harmed parties'] }, + created_at: { type: GraphQLDateTime }, implicated_systems: { type: new GraphQLList(GraphQLString) }, date: { type: new GraphQLNonNull(GraphQLString) }, description: { type: GraphQLString }, diff --git a/site/gatsby-site/server/types/notification.ts b/site/gatsby-site/server/types/notification.ts index cc6cf7ad28..2a7d489d39 100644 --- a/site/gatsby-site/server/types/notification.ts +++ b/site/gatsby-site/server/types/notification.ts @@ -16,5 +16,6 @@ export const NotificationType = new GraphQLObjectType({ sentDate: { type: GraphQLDateTime }, type: { type: GraphQLString }, userId: getRelationshipConfig(UserType, GraphQLString, 'userId', 'userId', 'users', 'customData'), + created_at: { type: GraphQLDateTime }, }), }); \ No newline at end of file diff --git a/site/gatsby-site/server/types/report.ts b/site/gatsby-site/server/types/report.ts index 05811bfc0b..2235473278 100644 --- a/site/gatsby-site/server/types/report.ts +++ b/site/gatsby-site/server/types/report.ts @@ -1,5 +1,5 @@ import { GraphQLBoolean, GraphQLInt, GraphQLList, GraphQLNonNull, GraphQLObjectType, GraphQLString } from "graphql"; -import { DateTimeResolver } from "graphql-scalars"; +import { DateTimeResolver, GraphQLDateTime } from "graphql-scalars"; import { ObjectIdScalar } from "../scalars"; import { getRelationshipConfig } from "../utils"; import { Context } from "../interfaces"; @@ -20,6 +20,7 @@ export const ReportType = new GraphQLObjectType({ _id: { type: ObjectIdScalar }, authors: { type: new GraphQLNonNull(new GraphQLList(GraphQLString)) }, cloudinary_id: { type: new GraphQLNonNull(GraphQLString) }, + created_at: { type: GraphQLDateTime }, date_downloaded: { type: new GraphQLNonNull(DateTimeResolver) }, date_modified: { type: new GraphQLNonNull(DateTimeResolver) }, date_published: { type: new GraphQLNonNull(DateTimeResolver) }, diff --git a/site/gatsby-site/server/types/reportHistory.ts b/site/gatsby-site/server/types/reportHistory.ts index 14f8ccbd1d..e3899ebfde 100644 --- a/site/gatsby-site/server/types/reportHistory.ts +++ b/site/gatsby-site/server/types/reportHistory.ts @@ -1,5 +1,5 @@ import { GraphQLBoolean, GraphQLInt, GraphQLList, GraphQLNonNull, GraphQLObjectType, GraphQLString } from "graphql"; -import { DateTimeResolver } from "graphql-scalars"; +import { DateTimeResolver, GraphQLDateTime } from "graphql-scalars"; import { ObjectIdScalar } from "../scalars"; import { EmbeddingType } from "./types"; @@ -9,6 +9,7 @@ export const ReportHistoryType = new GraphQLObjectType({ _id: { type: ObjectIdScalar }, authors: { type: new GraphQLList(GraphQLString) }, cloudinary_id: { type: GraphQLString }, + created_at: { type: GraphQLDateTime }, date_downloaded: { type: new GraphQLNonNull(DateTimeResolver) }, date_modified: { type: new GraphQLNonNull(DateTimeResolver) }, date_published: { type: new GraphQLNonNull(DateTimeResolver) },