Skip to content

Commit

Permalink
Remove Event (originally added for audits, unused)
Browse files Browse the repository at this point in the history
  • Loading branch information
pwalsh committed Feb 7, 2022
1 parent 3febfb4 commit bc8d109
Show file tree
Hide file tree
Showing 14 changed files with 52 additions and 223 deletions.
2 changes: 0 additions & 2 deletions src/core/events/index.ts

This file was deleted.

49 changes: 0 additions & 49 deletions src/core/events/models.ts

This file was deleted.

40 changes: 0 additions & 40 deletions src/core/events/repositories.ts

This file was deleted.

3 changes: 0 additions & 3 deletions src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { internalServerError, notFound } from '../middlewares';
import type { ModelDefinition, PluginBase } from '../types';
import { CommunicationModel, CommunicationRepository } from './communications';
import { DepartmentModel, DepartmentRepository, departmentRouter } from './departments';
import { EventModel, EventRepository } from './events';
import { JurisdictionModel, JurisdictionRepository, jurisdictionRouter } from './jurisdictions';
import { open311Router } from './open311';
import { ServiceRequestCommentModel, ServiceRequestModel, ServiceRequestRepository, serviceRequestRouter } from './service-requests';
Expand All @@ -32,7 +31,6 @@ const coreModels: ModelDefinition[] = [
ServiceRequestCommentModel,
ServiceModel,
StaffUserModel,
EventModel,
CommunicationModel,
DepartmentModel,
]
Expand All @@ -42,7 +40,6 @@ const coreRepositories: PluginBase[] = [
ServiceRequestRepository,
ServiceRepository,
StaffUserRepository,
EventRepository,
CommunicationRepository,
DepartmentRepository
]
Expand Down
28 changes: 0 additions & 28 deletions src/core/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,6 @@ export function isValidToSchema(schema: JSONSchema): (value: JSONBTarget) => Val
}
}

export const eventActorSchema: JSONSchema = {
'$schema': 'https://json-schema.org/draft/2020-12/schema',
'$id': `${homepage}/src/core/schemas/event-actor-schema.json`,
'title': 'Event Actor Schema',
'description': 'Event actors initiate events, and are users or the system itself.',
'type': 'object',
'required': ['id', 'name', 'type'],
'properties': {
'id': { 'type': 'string' },
'name': { 'type': 'string' },
'type': { 'type': 'string' },
}
}

export const eventSenderSchema: JSONSchema = {
'$schema': 'https://json-schema.org/draft/2020-12/schema',
'$id': `${homepage}/src/core/schemas/event-sender-schema.json`,
'title': 'Event Sender Schema',
'description': 'Event senders are subsystems that events are triggered from.',
'type': 'object',
'required': ['id', 'name', 'type'],
'properties': {
'id': { 'type': 'string' },
'module': { 'type': 'string' },
'callable': { 'type': 'string' },
}
}

export const serviceExtraAttrsSchema: JSONSchema = {
'$schema': 'https://json-schema.org/draft/2020-12/schema',
'$id': `${homepage}/src/core/schemas/service-attr-schema.json`,
Expand Down
4 changes: 0 additions & 4 deletions src/db/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ function applyCoreModelRelations(models: Models) {
Jurisdiction,
StaffUser,
ServiceRequestComment,
Event,
Communication,
Department
} = models;
Expand All @@ -39,9 +38,6 @@ function applyCoreModelRelations(models: Models) {
Jurisdiction.hasMany(ServiceRequest, { as: 'requests', foreignKey: 'jurisdictionId' });
ServiceRequest.belongsTo(Jurisdiction, { as: 'jurisdiction' });

Jurisdiction.hasMany(Event, { as: 'events', foreignKey: 'jurisdictionId' });
Event.belongsTo(Jurisdiction, { as: 'jurisdiction' });

Service.hasMany(ServiceRequest, { as: 'requests', foreignKey: 'serviceId' });
ServiceRequest.belongsTo(Service, { as: 'service' });

Expand Down
47 changes: 47 additions & 0 deletions src/migrations/10_remove_events.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import type { QueryInterface } from 'sequelize';
import { DataTypes } from 'sequelize';

export async function up({ context: queryInterface }: Record<string, QueryInterface>): Promise<void> {
await queryInterface.dropTable('Event');
}

export async function down({ context: queryInterface }: Record<string, QueryInterface>): Promise<void> {
await queryInterface.createTable('Event', {
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
allowNull: false,
primaryKey: true,
},
sender: {
type: DataTypes.JSONB,
allowNull: false,
},
actor: {
type: DataTypes.JSONB,
allowNull: false,
},
message: {
type: DataTypes.STRING,
allowNull: false,
},
createdAt: {
allowNull: false,
type: DataTypes.DATE
},
updatedAt: {
allowNull: false,
type: DataTypes.DATE
},
jurisdictionId: {
type: DataTypes.STRING,
onDelete: 'CASCADE',
references: {
model: 'Jurisdiction',
key: 'id',
}
},
});
await queryInterface.addIndex('Event', ['createdAt']);
await queryInterface.addIndex('Event', ['updatedAt']);
}
6 changes: 1 addition & 5 deletions src/registry/repositories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ import { Container } from 'inversify';
import { CommunicationRepository } from '../core/communications';
import { CommunicationService } from '../core/communications/services';
import { DepartmentRepository } from '../core/departments';
import { EventRepository } from '../core/events';
import { JurisdictionRepository } from '../core/jurisdictions';
import { Open311ServiceRepository, Open311ServiceRequestRepository } from '../core/open311';
import { ServiceRequestRepository } from '../core/service-requests';
import { ServiceRepository } from '../core/services';
import { StaffUserRepository } from '../core/staff-users';
import type { AppSettings, ICommunicationRepository, ICommunicationService, IDepartmentRepository, IEventRepository, IJurisdictionRepository, IOpen311ServiceRepository, IOpen311ServiceRequestRepository, IServiceRepository, IServiceRequestRepository, IStaffUserRepository, Plugin, Services } from '../types';
import type { AppSettings, ICommunicationRepository, ICommunicationService, IDepartmentRepository, IJurisdictionRepository, IOpen311ServiceRepository, IOpen311ServiceRequestRepository, IServiceRepository, IServiceRequestRepository, IStaffUserRepository, Plugin, Services } from '../types';
import { DatabaseEngine, Models, Repositories } from '../types';
import { appIds, repositoryIds, serviceIds } from './service-identifiers';

Expand Down Expand Up @@ -37,7 +36,6 @@ function bindRepositoriesWithPlugins(
repositoryContainer.bind<IOpen311ServiceRequestRepository>(repositoryIds.IOpen311ServiceRequestRepository).to(
Open311ServiceRequestRepository
);
repositoryContainer.bind<IEventRepository>(repositoryIds.IEventRepository).to(EventRepository);
repositoryContainer.bind<ICommunicationRepository>(repositoryIds.ICommunicationRepository).to(
CommunicationRepository
);
Expand All @@ -63,7 +61,6 @@ function bindRepositoriesWithPlugins(
const Open311ServiceRequest = repositoryContainer.get<IOpen311ServiceRequestRepository>(
repositoryIds.IOpen311ServiceRequestRepository
);
const Event = repositoryContainer.get<IEventRepository>(repositoryIds.IEventRepository);
const Communication = repositoryContainer.get<ICommunicationRepository>(repositoryIds.ICommunicationRepository);
const Department = repositoryContainer.get<IDepartmentRepository>(repositoryIds.IDepartmentRepository);

Expand All @@ -74,7 +71,6 @@ function bindRepositoriesWithPlugins(
ServiceRequest,
Open311Service,
Open311ServiceRequest,
Event,
Communication,
Department
}
Expand Down
27 changes: 1 addition & 26 deletions src/tools/fake-data-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import faker from 'faker';
import type { Sequelize } from 'sequelize/types';
import { REQUEST_STATUS_KEYS } from '../core/service-requests';
import { STAFF_USER_PERMISSIONS } from '../core/staff-users';
import { CommunicationAttributes, DepartmentAttributes, EventAttributes, JurisdictionAttributes, ServiceAttributes, ServiceRequestAttributes, ServiceRequestCommentAttributes, ServiceRequestInstance, StaffUserAttributes, TestDataMakerOptions, TestDataPayload } from '../types';
import { CommunicationAttributes, DepartmentAttributes, JurisdictionAttributes, ServiceAttributes, ServiceRequestAttributes, ServiceRequestCommentAttributes, ServiceRequestInstance, StaffUserAttributes, TestDataMakerOptions, TestDataPayload } from '../types';

/* eslint-disable */
function factory(generator: Function, times: number, generatorOpts: {}) {
Expand Down Expand Up @@ -96,24 +96,6 @@ function makeServiceRequestComment() {
} as ServiceRequestCommentAttributes
}

function makeEvent(options: Partial<TestDataMakerOptions>) {
return {
id: faker.datatype.uuid(),
sender: {
id: faker.datatype.uuid(),
name: faker.datatype.string(),
type: faker.datatype.string()
},
message: faker.lorem.sentences(3),
actor: {
id: faker.datatype.uuid(),
name: faker.datatype.string(),
type: faker.datatype.string()
},
jurisdictionId: options.jurisdiction?.id,
} as EventAttributes
}

function makeCommunication(options: Partial<TestDataMakerOptions>) {
return {
id: faker.datatype.uuid(),
Expand Down Expand Up @@ -166,10 +148,6 @@ export async function writeTestDataToDatabase(databaseEngine: Sequelize, testDat
}
}

for (const eventData of testData.events) {
await Event.create(eventData);
}

for (const communicationData of testData.communications) {
await Communication.create(communicationData);
}
Expand All @@ -185,7 +163,6 @@ export default function makeTestData(): TestDataPayload {
let staffUsers: StaffUserAttributes[] = [];
let services: ServiceAttributes[] = [];
let serviceRequests: ServiceRequestAttributes[] = [];
let events: EventAttributes[] = [];
let communications: CommunicationAttributes[] = [];
let departments: DepartmentAttributes[] = [];

Expand All @@ -200,7 +177,6 @@ export default function makeTestData(): TestDataPayload {
makeServiceRequest, 20, { staffUsers, services, jurisdiction }
) as unknown as ServiceRequestAttributes[]
)
events = events.concat(factory(makeEvent, 20, { jurisdiction }) as unknown as EventAttributes[])
departments = departments.concat(
factory(makeDepartment, 20, { jurisdiction }) as unknown as DepartmentAttributes[]
)
Expand All @@ -218,7 +194,6 @@ export default function makeTestData(): TestDataPayload {
staffUsers,
services,
serviceRequests,
events,
communications,
departments
}
Expand Down
15 changes: 0 additions & 15 deletions src/types/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,6 @@ export interface ServiceRequestCommentInstance
extends Model<ServiceRequestCommentAttributes, ServiceRequestCommentCreateAttributes>,
ServiceRequestCommentAttributes {}

export interface EventAttributes {
id: string;
sender: Record<string, string>;
actor: Record<string, string>;
message: string;
jurisdictionId: string;
}

export type EventCreateAttributes = Partial<EventAttributes>

export interface EventInstance
extends Model<EventAttributes, EventCreateAttributes>, EventAttributes {}

export interface CommunicationAttributes {
id?: string;
channel: string;
Expand Down Expand Up @@ -182,7 +169,6 @@ export interface TestDataPayload {
staffUsers: StaffUserAttributes[],
services: ServiceAttributes[],
serviceRequests: ServiceRequestAttributes[],
events: EventAttributes[],
communications: CommunicationAttributes[],
departments: DepartmentAttributes[],
}
Expand All @@ -194,5 +180,4 @@ export interface TestDataMakerOptions {
staffUsers: StaffUserAttributes[],
services: ServiceAttributes[],
serviceRequests: ServiceRequestAttributes[],
events: EventAttributes[],
}
3 changes: 1 addition & 2 deletions src/types/db.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Model, ModelAttributes, ModelCtor, ModelOptions, QueryInterface, Sequelize } from "sequelize/types";
import { Umzug } from "umzug";
import { CommunicationAttributes, CommunicationCreateAttributes, DepartmentAttributes, DepartmentCreateAttributes, EventAttributes, EventCreateAttributes, JurisdictionAttributes, JurisdictionCreateAttributes, ServiceAttributes, ServiceCreateAttributes, ServiceRequestAttributes, ServiceRequestCommentAttributes, ServiceRequestCommentCreateAttributes, ServiceRequestCreateAttributes, StaffUserAttributes, StaffUserCreateAttributes } from ".";
import { CommunicationAttributes, CommunicationCreateAttributes, DepartmentAttributes, DepartmentCreateAttributes, JurisdictionAttributes, JurisdictionCreateAttributes, ServiceAttributes, ServiceCreateAttributes, ServiceRequestAttributes, ServiceRequestCommentAttributes, ServiceRequestCommentCreateAttributes, ServiceRequestCreateAttributes, StaffUserAttributes, StaffUserCreateAttributes } from ".";

export type DatabaseEngine = Sequelize;
export type MigrationEngine = Umzug<QueryInterface>;
Expand Down Expand Up @@ -37,7 +37,6 @@ export interface Models {
Service: ModelCtor<Model<ServiceAttributes, ServiceCreateAttributes>>,
ServiceRequest: ModelCtor<Model<ServiceRequestAttributes, ServiceRequestCreateAttributes>>,
ServiceRequestComment: ModelCtor<Model<ServiceRequestCommentAttributes, ServiceRequestCommentCreateAttributes>>,
Event: ModelCtor<Model<EventAttributes, EventCreateAttributes>>,
Communication: ModelCtor<Model<CommunicationAttributes, CommunicationCreateAttributes>>,
Department: ModelCtor<Model<DepartmentAttributes, DepartmentCreateAttributes>>,
}
Loading

0 comments on commit bc8d109

Please sign in to comment.