Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/api/drizzle/0059_resource_capacity_source.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE resources ADD COLUMN capacity integer, ADD COLUMN occupancy integer, ADD COLUMN source_organisation text, ADD COLUMN source_url text;
180 changes: 180 additions & 0 deletions apps/api/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -10257,6 +10257,26 @@
"example": "Caracas",
"description": "City name"
},
"capacity": {
"type": "number",
"example": 200,
"description": "Total capacity of the place (e.g. shelter beds)"
},
"occupancy": {
"type": "number",
"example": 120,
"description": "Current occupancy of the place"
},
"sourceOrganisation": {
"type": "string",
"example": "Protección Civil",
"description": "Organisation that is the source of this record"
},
"sourceUrl": {
"type": "string",
"example": "https://example.org/refugios/123",
"description": "URL of the source record"
},
"isFinalRecipient": {
"type": "boolean",
"example": true,
Expand Down Expand Up @@ -10414,6 +10434,26 @@
"description": "Nuevo horario. Cadena vacía lo borra. Omitir para no cambiarlo.",
"nullable": true
},
"capacity": {
"type": "number",
"description": "Nueva capacidad total. Omitir para no cambiarla.",
"example": 200
},
"occupancy": {
"type": "number",
"description": "Nueva ocupación actual. Omitir para no cambiarla.",
"example": 120
},
"sourceOrganisation": {
"type": "string",
"description": "Nueva organización de origen. Cadena vacía la borra. Omitir para no cambiarla.",
"nullable": true
},
"sourceUrl": {
"type": "string",
"description": "Nueva URL de origen. Cadena vacía la borra. Omitir para no cambiarla.",
"nullable": true
},
"location": {
"description": "Nueva ubicación (dirección + coordenadas) para corregir la geolocalización. Omitir para no cambiarla.",
"allOf": [
Expand Down Expand Up @@ -10639,6 +10679,30 @@
"example": "Caracas",
"nullable": true
},
"capacity": {
"type": "number",
"example": 200,
"nullable": true,
"description": "Total capacity of the place (e.g. shelter beds)"
},
"occupancy": {
"type": "number",
"example": 120,
"nullable": true,
"description": "Current occupancy of the place"
},
"sourceOrganisation": {
"type": "string",
"example": "Protección Civil",
"nullable": true,
"description": "Organisation that is the source of this record"
},
"sourceUrl": {
"type": "string",
"example": "https://example.org/refugios/123",
"nullable": true,
"description": "URL of the source record"
},
"isFinalRecipient": {
"type": "boolean",
"example": false,
Expand Down Expand Up @@ -10680,6 +10744,10 @@
"externalUpdatedAt",
"country",
"city",
"capacity",
"occupancy",
"sourceOrganisation",
"sourceUrl",
"isFinalRecipient",
"recipientType",
"disputed",
Expand Down Expand Up @@ -11015,6 +11083,30 @@
"example": "Caracas",
"nullable": true
},
"capacity": {
"type": "number",
"example": 200,
"nullable": true,
"description": "Total capacity of the place (e.g. shelter beds)"
},
"occupancy": {
"type": "number",
"example": 120,
"nullable": true,
"description": "Current occupancy of the place"
},
"sourceOrganisation": {
"type": "string",
"example": "Protección Civil",
"nullable": true,
"description": "Organisation that is the source of this record"
},
"sourceUrl": {
"type": "string",
"example": "https://example.org/refugios/123",
"nullable": true,
"description": "URL of the source record"
},
"isFinalRecipient": {
"type": "boolean",
"example": false,
Expand Down Expand Up @@ -11061,6 +11153,10 @@
"externalUpdatedAt",
"country",
"city",
"capacity",
"occupancy",
"sourceOrganisation",
"sourceUrl",
"isFinalRecipient",
"recipientType",
"disputed",
Expand Down Expand Up @@ -11237,6 +11333,30 @@
"example": "Caracas",
"nullable": true
},
"capacity": {
"type": "number",
"example": 200,
"nullable": true,
"description": "Total capacity of the place (e.g. shelter beds)"
},
"occupancy": {
"type": "number",
"example": 120,
"nullable": true,
"description": "Current occupancy of the place"
},
"sourceOrganisation": {
"type": "string",
"example": "Protección Civil",
"nullable": true,
"description": "Organisation that is the source of this record"
},
"sourceUrl": {
"type": "string",
"example": "https://example.org/refugios/123",
"nullable": true,
"description": "URL of the source record"
},
"isFinalRecipient": {
"type": "boolean",
"example": false,
Expand Down Expand Up @@ -11289,6 +11409,10 @@
"externalUpdatedAt",
"country",
"city",
"capacity",
"occupancy",
"sourceOrganisation",
"sourceUrl",
"isFinalRecipient",
"recipientType",
"disputed",
Expand Down Expand Up @@ -11444,6 +11568,30 @@
"example": "Caracas",
"nullable": true
},
"capacity": {
"type": "number",
"example": 200,
"nullable": true,
"description": "Total capacity of the place (e.g. shelter beds)"
},
"occupancy": {
"type": "number",
"example": 120,
"nullable": true,
"description": "Current occupancy of the place"
},
"sourceOrganisation": {
"type": "string",
"example": "Protección Civil",
"nullable": true,
"description": "Organisation that is the source of this record"
},
"sourceUrl": {
"type": "string",
"example": "https://example.org/refugios/123",
"nullable": true,
"description": "URL of the source record"
},
"isFinalRecipient": {
"type": "boolean",
"example": false,
Expand Down Expand Up @@ -11507,6 +11655,10 @@
"externalUpdatedAt",
"country",
"city",
"capacity",
"occupancy",
"sourceOrganisation",
"sourceUrl",
"isFinalRecipient",
"recipientType",
"disputed",
Expand Down Expand Up @@ -11656,6 +11808,30 @@
"example": "Caracas",
"nullable": true
},
"capacity": {
"type": "number",
"example": 200,
"nullable": true,
"description": "Total capacity of the place (e.g. shelter beds)"
},
"occupancy": {
"type": "number",
"example": 120,
"nullable": true,
"description": "Current occupancy of the place"
},
"sourceOrganisation": {
"type": "string",
"example": "Protección Civil",
"nullable": true,
"description": "Organisation that is the source of this record"
},
"sourceUrl": {
"type": "string",
"example": "https://example.org/refugios/123",
"nullable": true,
"description": "URL of the source record"
},
"isFinalRecipient": {
"type": "boolean",
"example": false,
Expand Down Expand Up @@ -11737,6 +11913,10 @@
"externalUpdatedAt",
"country",
"city",
"capacity",
"occupancy",
"sourceOrganisation",
"sourceUrl",
"isFinalRecipient",
"recipientType",
"disputed",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,42 @@ describe('EditResource', () => {
expect(result.changes).toHaveLength(2);
});

it('edits capacity, occupancy, source organisation and source url', async () => {
const id = await seed();

const result = await editResource.execute({
resourceId: id,
capacity: 200,
occupancy: 120,
sourceOrganisation: 'Protección Civil',
sourceUrl: 'https://example.org/refugios/123',
});

const resource = await repo.findById(ResourceId.fromString(id));
expect(resource!.capacity).toBe(200);
expect(resource!.occupancy).toBe(120);
expect(resource!.sourceOrganisation).toBe('Protección Civil');
expect(resource!.sourceUrl).toBe('https://example.org/refugios/123');

expect(result.changes).toEqual(
expect.arrayContaining([
{ field: 'capacity', before: null, after: 200 },
{ field: 'occupancy', before: null, after: 120 },
{
field: 'sourceOrganisation',
before: null,
after: 'Protección Civil',
},
{
field: 'sourceUrl',
before: null,
after: 'https://example.org/refugios/123',
},
]),
);
expect(result.changes).toHaveLength(4);
});

it('clears the contact when an empty string is given', async () => {
const id = await seed();
await editResource.execute({ resourceId: id, contact: '+58 212 555' });
Expand Down
17 changes: 17 additions & 0 deletions apps/api/src/contexts/resources/application/edit-resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ export interface EditResourceCommand {
description?: string | null;
contact?: string | null;
schedule?: string | null;
capacity?: number | null;
occupancy?: number | null;
sourceOrganisation?: string | null;
sourceUrl?: string | null;
location?: LocationProps;
}

Expand All @@ -36,6 +40,10 @@ export class EditResource {
description: resource.description,
contact: resource.contact,
schedule: resource.schedule,
capacity: resource.capacity,
occupancy: resource.occupancy,
sourceOrganisation: resource.sourceOrganisation,
sourceUrl: resource.sourceUrl,
address: resource.location.toPlain().address,
latitude: resource.location.toPlain().latitude,
longitude: resource.location.toPlain().longitude,
Expand All @@ -46,6 +54,11 @@ export class EditResource {
if (cmd.description !== undefined) edit.description = cmd.description;
if (cmd.contact !== undefined) edit.contact = cmd.contact;
if (cmd.schedule !== undefined) edit.schedule = cmd.schedule;
if (cmd.capacity !== undefined) edit.capacity = cmd.capacity;
if (cmd.occupancy !== undefined) edit.occupancy = cmd.occupancy;
if (cmd.sourceOrganisation !== undefined)
edit.sourceOrganisation = cmd.sourceOrganisation;
if (cmd.sourceUrl !== undefined) edit.sourceUrl = cmd.sourceUrl;
if (cmd.location !== undefined)
edit.location = Location.create(cmd.location);
resource.edit(edit);
Expand All @@ -55,6 +68,10 @@ export class EditResource {
description: resource.description,
contact: resource.contact,
schedule: resource.schedule,
capacity: resource.capacity,
occupancy: resource.occupancy,
sourceOrganisation: resource.sourceOrganisation,
sourceUrl: resource.sourceUrl,
address: resource.location.toPlain().address,
latitude: resource.location.toPlain().latitude,
longitude: resource.location.toPlain().longitude,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ describe('GetPublicResources', () => {
accepts: [],
country: null,
city: null,
capacity: null,
occupancy: null,
sourceOrganisation: null,
sourceUrl: null,
provenance: null,
isFinalRecipient: false,
recipientType: null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ function hiddenResourceWithInventory(): Resource {
accepts: [],
country: null,
city: null,
capacity: null,
occupancy: null,
sourceOrganisation: null,
sourceUrl: null,
provenance: null,
isFinalRecipient: false,
recipientType: null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,10 @@ describe('IngestExternalResources', () => {
accepts: [],
country: null,
city: null,
capacity: null,
occupancy: null,
sourceOrganisation: null,
sourceUrl: null,
provenance: {
sourceName: SOURCE_NAME,
externalId: EXT_ID_1,
Expand Down Expand Up @@ -304,6 +308,10 @@ describe('IngestExternalResources', () => {
accepts: [],
country: null,
city: null,
capacity: null,
occupancy: null,
sourceOrganisation: null,
sourceUrl: null,
provenance: {
sourceName: SOURCE_NAME,
externalId: EXT_ID_1,
Expand Down
Loading
Loading