Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
6fac552
created entities
mehanana Sep 18, 2026
8fd8ec8
added entities to data source
mehanana Sep 18, 2026
d7a579c
migrations + some small fixes to make migration work
mehanana Sep 18, 2026
6a85218
update dependencies
mehanana Sep 18, 2026
8c782f0
linter fix
mehanana Sep 18, 2026
46c11bd
normalize line endings to LF with .gitattributes
mehanana Sep 18, 2026
2be6e61
changed codeowners
mehanana Sep 18, 2026
bd22cc4
changed codeowners
mehanana Sep 18, 2026
86b5f35
fixed small linter errors
mehanana Sep 19, 2026
587fb98
Merge branch 'main' into create-database
mehanana Sep 19, 2026
9899502
Merge pull request #4 from Code-4-Community/create-database
saumyapalk23 Sep 19, 2026
1bbd015
swagger setup
mehanana Sep 23, 2026
dc04b55
added mock data
mehanana Sep 23, 2026
fa86bba
remove the extra user.entity file
mehanana Sep 23, 2026
a1bfc15
added GET sites endpoint
jxuistrying Oct 7, 2026
17fc203
add GET /stewardEvent endpoint for steward-published events
ducan-le Oct 13, 2026
99b28eb
Merge pull request #14 from Code-4-Community/feature/bffc-1-get-site-…
jxuistrying Oct 14, 2026
7c3e964
added endpoint, filtering and tests
anjali-silina Oct 14, 2026
f536bb7
added @types/express
anjali-silina Oct 21, 2026
ba46280
added endpoint and tests
anjali-silina Oct 21, 2026
2d07440
create and register new recurring event entity
bodhiYG Oct 21, 2026
1f9b2e4
add new image column to plant inventory entity
bodhiYG Oct 21, 2026
bdf3157
recurring event entity fixes
bodhiYG Oct 21, 2026
763a556
migration
bodhiYG Oct 21, 2026
a2f50f1
mock data
bodhiYG Oct 21, 2026
d282984
Merge remote-tracking branch 'origin/main' into bffc-3-get-stewardEve…
ducan-le Oct 22, 2026
6bff8c1
simplify steward events module and tests
ducan-le Oct 22, 2026
4aea387
Add GET /media/:siteId endpoint
piersolh Oct 28, 2026
672ead6
Track media uploader per item via uploaded_by FK
piersolh Oct 28, 2026
2339599
Move uploaded_by into its own migration
piersolh Oct 28, 2026
8bb2ab0
remove unecessary tests
piersolh Oct 28, 2026
47d3fb8
small column/field changes to reccurring events entity + migration
bodhiYG Oct 28, 2026
8b91bc5
db entity changes, api changes, and seed data changes
bodhiYG Oct 28, 2026
88c61a5
migration
bodhiYG Oct 28, 2026
3f7d831
api response changes
bodhiYG Oct 28, 2026
50ac8d6
small mock data changes
bodhiYG Oct 28, 2026
20fd163
Remove eventType from steward-event-response DTO
ducan-le Oct 30, 2026
3f7c19f
Add @Public() decorator to GET endpoint
ducan-le Oct 30, 2026
f42e2e1
Update findBySite to return detailed event data
ducan-le Oct 30, 2026
468c14f
update entities
piersolh Oct 30, 2026
bc9972c
update BE pagination
piersolh Nov 3, 2026
5a3c3ad
add public change
anjali-silina Nov 4, 2026
fdd319f
remove migrations, eventType and steward events, added public
anjali-silina Nov 4, 2026
8ac3363
update query to reflect on delete set null
piersolh Nov 4, 2026
a6cf975
Merge pull request #24 from Code-4-Community/#6-get-announcement-id
anjalisilina Nov 5, 2026
f6c62ba
Merge branch 'main' into piersol-get-image-by-site-id
piersolh Nov 5, 2026
fa08f0e
Merge pull request #28 from Code-4-Community/piersol-get-image-by-sit…
saumyapalk23 Nov 5, 2026
c9f32c9
Merge branch 'main' into #2-get-list-staff
anjalisilina Nov 10, 2026
e31e097
Merge pull request #23 from Code-4-Community/#2-get-list-staff
anjalisilina Nov 10, 2026
6c3e980
Add Public decorator to steward-events controller
ducan-le Nov 10, 2026
bb3dc97
update steward events tests to remove eventType and fix Public import
ducan-le Nov 10, 2026
f570060
format steward events service
ducan-le Nov 10, 2026
9688d6d
Add Cognito admin user management to CognitoService
piersolh Nov 10, 2026
8836428
Merge origin/main into bg-17-update-database-tables
bodhiYG Nov 18, 2026
6bc11c2
Merge pull request #26 from Code-4-Community/bg-15-update-database-sc…
bodhiYG Nov 18, 2026
95f15e9
Merge origin/main into bg-17-update-database-tables
bodhiYG Nov 18, 2026
99a0e4f
Merge pull request #29 from Code-4-Community/bg-17-update-database-ta…
bodhiYG Nov 18, 2026
17d73a9
Merge pull request #32 from Code-4-Community/piersol-cognito-auth
piersolh Nov 18, 2026
5c18433
Merge branch 'main' into bffc-3-get-stewardEvent-list-steward-publish…
ducan-le Nov 22, 2026
e66970f
Change time fields to startTime and endTime
ducan-le Nov 22, 2026
7abc257
Update event time properties in findBySite method
ducan-le Nov 22, 2026
b6c5097
Update time property to startTime and add endTime
ducan-le Nov 22, 2026
f6edd27
Rename time to startTime and add endTime
ducan-le Nov 22, 2026
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 .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=lf
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @maxn990
* @mehanana @saumyapalk23
Empty file.
24 changes: 24 additions & 0 deletions apps/backend/src/announcements/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Announcements

Stewards publish announcements (upcoming events, workdays, what is ripe, etc.). `GET /api/announcement/{site_id}` surfaces those posts on the public per-site detail page so visitors can stay informed.

## `GET /api/announcement/{site_id}`

**Auth:** `@Public()` — visitors can call this without a Bearer token (site detail page).

**Path:** `site_id` must be a UUID. A non-UUID value is `400`.

**Response:** JSON array, newest published date first (then `id` for a stable tie-break). Empty `[]` when the site exists but has no announcements — not `404`. Unknown `site_id` → `404`.

Each element:

| Field | Notes |
| --------- | ------------------------------------------ |
| `id` | Announcement UUID |
| `content` | Body text (`info` column) |
| `date` | Date published (`YYYY-MM-DD`) |
| `author` | Posting steward `{ id, name }` (no email) |

Pruning old announcements is out of scope for this endpoint (later priority).

Swagger: tag **Announcements**. Enable with `SWAGGER_ENABLED=true` and open `/api`.
68 changes: 68 additions & 0 deletions apps/backend/src/announcements/announcements.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { Test, TestingModule } from '@nestjs/testing';
import { NotFoundException } from '@nestjs/common';

import { IS_PUBLIC_KEY } from '../aws/cognito/cognito.decorator';
import { AnnouncementsController } from './announcements.controller';
import { AnnouncementsService } from './announcements.service';
import { AnnouncementResponseDto } from './dto/announcement-response.dto';

describe('AnnouncementsController', () => {
let controller: AnnouncementsController;
let mockService: { findAllBySiteId: jest.Mock };

const siteId = '1a3cc442-d41f-421d-af8e-311781e6c033';
const sample: AnnouncementResponseDto[] = [
{
id: 'ann-1',
content: 'Paw paws are ripe — come pick this weekend.',
date: '2026-10-12',
author: { id: 'steward-id', name: 'Jamie Chen' },
},
];

beforeEach(async () => {
mockService = { findAllBySiteId: jest.fn() };

const module: TestingModule = await Test.createTestingModule({
controllers: [AnnouncementsController],
providers: [{ provide: AnnouncementsService, useValue: mockService }],
}).compile();

controller = module.get(AnnouncementsController);
});

it('marks GET /announcement/:site_id as @Public()', () => {
const isPublic = Reflect.getMetadata(
IS_PUBLIC_KEY,
AnnouncementsController.prototype.getAnnouncementsBySite,
);
expect(isPublic).toBe(true);
});

it('forwards site_id and returns the service result', async () => {
mockService.findAllBySiteId.mockResolvedValue(sample);

await expect(controller.getAnnouncementsBySite(siteId)).resolves.toEqual(
sample,
);
expect(mockService.findAllBySiteId).toHaveBeenCalledWith(siteId);
});

it('returns an empty array when the site has no announcements', async () => {
mockService.findAllBySiteId.mockResolvedValue([]);

await expect(controller.getAnnouncementsBySite(siteId)).resolves.toEqual(
[],
);
});

it('propagates NotFoundException when the site does not exist', async () => {
mockService.findAllBySiteId.mockRejectedValue(
new NotFoundException('Site not found'),
);

await expect(
controller.getAnnouncementsBySite('00000000-0000-0000-0000-000000000000'),
).rejects.toThrow(NotFoundException);
});
});
43 changes: 43 additions & 0 deletions apps/backend/src/announcements/announcements.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { Controller, Get, Param, ParseUUIDPipe } from '@nestjs/common';
import {
ApiNotFoundResponse,
ApiOkResponse,
ApiOperation,
ApiParam,
ApiTags,
} from '@nestjs/swagger';

import { Public } from '../aws/cognito/cognito.decorator';
import { AnnouncementsService } from './announcements.service';
import { AnnouncementResponseDto } from './dto/announcement-response.dto';

@ApiTags('Announcements')
@Controller('announcement')
export class AnnouncementsController {
constructor(private readonly announcementsService: AnnouncementsService) {}

/**
* Public site-page list of steward announcements for one site.
*/
@Get(':site_id')
@Public()
@ApiOperation({
summary: 'List announcements for a site',
description:
'Returns steward-published announcements for the given site, newest first. ' +
'An empty array means the site exists but has no announcements. Unknown `site_id` is 404.',
})
@ApiParam({
name: 'site_id',
description: 'Site UUID',
type: 'string',
format: 'uuid',
})
@ApiOkResponse({ type: [AnnouncementResponseDto] })
@ApiNotFoundResponse({ description: 'Site not found' })
getAnnouncementsBySite(
@Param('site_id', ParseUUIDPipe) siteId: string,
): Promise<AnnouncementResponseDto[]> {
return this.announcementsService.findAllBySiteId(siteId);
}
}
14 changes: 14 additions & 0 deletions apps/backend/src/announcements/announcements.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';

import { Announcement } from '../entities/announcement.entity';
import { Site } from '../entities/site.entity';
import { AnnouncementsController } from './announcements.controller';
import { AnnouncementsService } from './announcements.service';

@Module({
imports: [TypeOrmModule.forFeature([Announcement, Site])],
controllers: [AnnouncementsController],
providers: [AnnouncementsService],
})
export class AnnouncementsModule {}
130 changes: 130 additions & 0 deletions apps/backend/src/announcements/announcements.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
import { Test, TestingModule } from '@nestjs/testing';
import { getRepositoryToken } from '@nestjs/typeorm';
import { NotFoundException } from '@nestjs/common';

import { Announcement } from '../entities/announcement.entity';
import { Site } from '../entities/site.entity';
import { User, UserType } from '../entities/user.entity';
import { AnnouncementsService } from './announcements.service';

const SITE_ID = '1a3cc442-d41f-421d-af8e-311781e6c033';

const steward = {
id: 'steward-uuid',
name: 'Jamie Chen',
email: 'jamie@example.com',
type: UserType.STEWARD,
} as User;

function announcement(
overrides: Partial<Announcement> & { id: string; date: string },
): Announcement {
return {
info: 'Announcement body',
steward,
site: { id: SITE_ID } as Site,
...overrides,
} as Announcement;
}

describe('AnnouncementsService', () => {
let service: AnnouncementsService;
let announcementRepo: { find: jest.Mock };
let siteRepo: { exists: jest.Mock };

beforeEach(async () => {
announcementRepo = { find: jest.fn().mockResolvedValue([]) };
siteRepo = { exists: jest.fn().mockResolvedValue(true) };

const module: TestingModule = await Test.createTestingModule({
providers: [
AnnouncementsService,
{
provide: getRepositoryToken(Announcement),
useValue: announcementRepo,
},
{ provide: getRepositoryToken(Site), useValue: siteRepo },
],
}).compile();

service = module.get(AnnouncementsService);
});

describe('findAllBySiteId', () => {
it('throws NotFoundException when the site does not exist', async () => {
siteRepo.exists.mockResolvedValue(false);

await expect(service.findAllBySiteId(SITE_ID)).rejects.toThrow(
NotFoundException,
);
expect(announcementRepo.find).not.toHaveBeenCalled();
});

it('returns an empty array when the site has no announcements', async () => {
announcementRepo.find.mockResolvedValue([]);

await expect(service.findAllBySiteId(SITE_ID)).resolves.toEqual([]);
expect(siteRepo.exists).toHaveBeenCalledWith({ where: { id: SITE_ID } });
});

it('maps content, date, and author without exposing steward email', async () => {
announcementRepo.find.mockResolvedValue([
announcement({
id: 'ann-ripe',
date: '2026-10-12',
info: 'Paw paws are ripe — come pick this weekend.',
}),
]);

const [result] = await service.findAllBySiteId(SITE_ID);

expect(result).toEqual({
id: 'ann-ripe',
content: 'Paw paws are ripe — come pick this weekend.',
date: '2026-10-12',
author: { id: steward.id, name: steward.name },
});
expect(result.author).not.toHaveProperty('email');
});

it('queries announcements for the site newest-first', async () => {
await service.findAllBySiteId(SITE_ID);

expect(announcementRepo.find).toHaveBeenCalledWith({
where: { site: { id: SITE_ID } },
relations: { steward: true },
order: { date: 'DESC', id: 'DESC' },
});
});

it('returns announcements in most-recent-first order', async () => {
announcementRepo.find.mockResolvedValue([
announcement({
id: 'newer',
date: '2026-10-12',
info: 'Paw paws are ripe — come pick this weekend.',
}),
announcement({
id: 'older',
date: '2026-09-20',
info: 'Path repairs scheduled for next week — expect partial closures.',
}),
]);

const results = await service.findAllBySiteId(SITE_ID);
expect(results.map((row) => row.id)).toEqual(['newer', 'older']);
});

it('normalizes TypeORM Date objects into YYYY-MM-DD', async () => {
announcementRepo.find.mockResolvedValue([
announcement({
id: 'date-obj',
date: new Date(2026, 9, 12) as unknown as string,
}),
]);

const [result] = await service.findAllBySiteId(SITE_ID);
expect(result.date).toBe('2026-10-12');
});
});
});
61 changes: 61 additions & 0 deletions apps/backend/src/announcements/announcements.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { Injectable, NotFoundException } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';

import { Announcement } from '../entities/announcement.entity';
import { Site } from '../entities/site.entity';
import { AnnouncementResponseDto } from './dto/announcement-response.dto';

@Injectable()
export class AnnouncementsService {
constructor(
@InjectRepository(Announcement)
private readonly announcementRepo: Repository<Announcement>,
@InjectRepository(Site)
private readonly siteRepo: Repository<Site>,
) {}

/**
* All announcements for `siteId`, newest published date first.
* Unknown site → 404. Known site with none → `[]`.
*/
async findAllBySiteId(siteId: string): Promise<AnnouncementResponseDto[]> {
const siteExists = await this.siteRepo.exists({ where: { id: siteId } });
if (!siteExists) {
throw new NotFoundException(`Site with ID ${siteId} not found`);
}

const announcements = await this.announcementRepo.find({
where: { site: { id: siteId } },
relations: { steward: true },
order: { date: 'DESC', id: 'DESC' },
});

return announcements.map((announcement) => this.mapToDto(announcement));
}

private mapToDto(announcement: Announcement): AnnouncementResponseDto {
return {
id: announcement.id,
content: announcement.info,
date: normalizeDate(announcement.date),
author: {
id: announcement.steward.id,
name: announcement.steward.name,
},
};
}
}

function pad2(n: number): string {
return String(n).padStart(2, '0');
}

function normalizeDate(value: string | Date): string {
if (value instanceof Date) {
return `${value.getFullYear()}-${pad2(value.getMonth() + 1)}-${pad2(
value.getDate(),
)}`;
}
return String(value).slice(0, 10);
}
34 changes: 34 additions & 0 deletions apps/backend/src/announcements/dto/announcement-response.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { ApiProperty } from '@nestjs/swagger';

export class AnnouncementAuthorDto {
@ApiProperty({ format: 'uuid' })
id: string;

@ApiProperty({ description: 'Steward who published the announcement' })
name: string;
}

/**
* One steward announcement on a public site detail page.
* `content` is the stored `info` column; `author` is the posting steward
* (id + name only — email is never returned).
*/
export class AnnouncementResponseDto {
@ApiProperty({ format: 'uuid' })
id: string;

@ApiProperty({
description:
'Announcement body (upcoming events, workdays, what is ripe, etc.)',
})
content: string;

@ApiProperty({
description: 'Date published (YYYY-MM-DD)',
example: '2026-10-12',
})
date: string;

@ApiProperty({ type: AnnouncementAuthorDto })
author: AnnouncementAuthorDto;
}
Loading
Loading