Skip to content

Commit

Permalink
Merge pull request #281 from esek/feat/hideactivity
Browse files Browse the repository at this point in the history
Added hidden flag functionality to activities
  • Loading branch information
Muncherkin authored Jan 15, 2025
2 parents d2256d4 + e4a79d6 commit a8c38ce
Show file tree
Hide file tree
Showing 13 changed files with 361 additions and 852 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ Alla märkbara ändringar ska dokumenteras i denna fil.
Baserat på [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
och följer [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.15.0]
- added hidden flag functionality to activities
- query activities to include or exclude hidden activities
- (obviously there are) changes made to activity graphql and prisma schemas, reducer, resolver and api

## [1.14.0]
- log changes to individualAccess and postAccess

Expand Down
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ ARG WORKING_DIR
# Create app directory
WORKDIR $WORKING_DIR

RUN apk add --no-cache openssl
# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
Expand Down Expand Up @@ -44,7 +45,7 @@ WORKDIR $WORKING_DIR

# Best practices
# https://github.com/nodejs/docker-node/blob/main/docs/BestPractices.md
RUN apk add --no-cache tini bash
RUN apk add --no-cache tini bash openssl
ENTRYPOINT [ "/sbin/tini", "--" ]

RUN wget https://raw.githubusercontent.com/vishnubob/wait-for-it/master/wait-for-it.sh; chmod +x wait-for-it.sh
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ekorre-ts",
"version": "1.14.0",
"version": "1.15.0",
"description": "E-Sektionens backend",
"main": "src/index.ts",
"scripts": {
Expand Down
15 changes: 15 additions & 0 deletions prisma/data/activity.seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ function getRandomDate(): Date {
return new Date(randomTime);
}

function getRandomBool(): boolean {
return Math.random() > 0.5;
}

export const activities: Prisma.PrismaActivityCreateInput[] = [
{
utskott: PrismaUtskott.CM,
Expand All @@ -18,6 +22,7 @@ export const activities: Prisma.PrismaActivityCreateInput[] = [
startDate: getRandomDate(),
locationTitle: '',
locationLink: '',
hidden: getRandomBool(),
},
{
utskott: PrismaUtskott.FVU,
Expand All @@ -28,6 +33,7 @@ export const activities: Prisma.PrismaActivityCreateInput[] = [
startDate: getRandomDate(),
locationTitle: '',
locationLink: '',
hidden: getRandomBool(),
},
{
utskott: PrismaUtskott.INFU,
Expand All @@ -38,6 +44,7 @@ export const activities: Prisma.PrismaActivityCreateInput[] = [
startDate: getRandomDate(),
locationTitle: '',
locationLink: '',
hidden: getRandomBool(),
},
{
utskott: PrismaUtskott.KM,
Expand All @@ -48,6 +55,7 @@ export const activities: Prisma.PrismaActivityCreateInput[] = [
startDate: getRandomDate(),
locationTitle: '',
locationLink: '',
hidden: getRandomBool(),
},
{
utskott: PrismaUtskott.NOLLU,
Expand All @@ -58,6 +66,7 @@ export const activities: Prisma.PrismaActivityCreateInput[] = [
startDate: getRandomDate(),
locationTitle: '',
locationLink: '',
hidden: getRandomBool(),
},
{
utskott: PrismaUtskott.ENU,
Expand All @@ -68,6 +77,7 @@ export const activities: Prisma.PrismaActivityCreateInput[] = [
startDate: getRandomDate(),
locationTitle: '',
locationLink: '',
hidden: getRandomBool(),
},
{
utskott: PrismaUtskott.PENGU,
Expand All @@ -78,6 +88,7 @@ export const activities: Prisma.PrismaActivityCreateInput[] = [
startDate: getRandomDate(),
locationTitle: '',
locationLink: '',
hidden: getRandomBool(),
},
{
utskott: PrismaUtskott.E6,
Expand All @@ -88,6 +99,7 @@ export const activities: Prisma.PrismaActivityCreateInput[] = [
startDate: getRandomDate(),
locationTitle: '',
locationLink: '',
hidden: getRandomBool(),
},
{
utskott: PrismaUtskott.SRE,
Expand All @@ -98,6 +110,7 @@ export const activities: Prisma.PrismaActivityCreateInput[] = [
startDate: getRandomDate(),
locationTitle: '',
locationLink: '',
hidden: getRandomBool(),
},
{
utskott: PrismaUtskott.STYRELSEN,
Expand All @@ -108,6 +121,7 @@ export const activities: Prisma.PrismaActivityCreateInput[] = [
startDate: getRandomDate(),
locationTitle: '',
locationLink: '',
hidden: getRandomBool(),
},
{
utskott: PrismaUtskott.OTHER,
Expand All @@ -118,5 +132,6 @@ export const activities: Prisma.PrismaActivityCreateInput[] = [
startDate: getRandomDate(),
locationTitle: '',
locationLink: '',
hidden: getRandomBool(),
},
];
73 changes: 38 additions & 35 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -28,41 +28,42 @@ model PrismaIndividualAccessLog {
resource String
isActive Boolean @map("is_active")
timestamp DateTime @default(now())
@@map("individual_accesses_log")
}

model PrismaUser {
username String @id
access PrismaIndividualAccess[] @relation(name: "PrismaIndividualAccessToPrismaUser")
grantedIndividualAccessLog PrismaIndividualAccessLog[] @relation(name: "PrismaIndividualAccessLogToPrismaUserGrantor")
grantedPostAccessLog PrismaPostAccessLog[] @relation(name: "PrismaPostAccessLogToPrismaUserGrantor")
targetIndividualAccessLog PrismaIndividualAccessLog[] @relation(name: "PrismaIndividualAccessLogToPrismaUserTarget")
articles PrismaArticle[] @relation(name: "PrismaArticleToAuthor")
editedArticles PrismaArticle[] @relation(name: "PrismaArticleToLastUpdateBy")
elections PrismaElection[] @relation(name: "PrismaElectionToPrismaUser")
nominations PrismaNomination[] @relation(name: "PrismaNominationToPrismaUser")
proposals PrismaProposal[] @relation(name: "PrismaProposalToPrismaUser")
files PrismaFile[] @relation(name: "PrismaFileToPrismaUser")
heHes PrismaHehe[] @relation(name: "PrismaHeheToPrismaUser")
postHistory PrismaPostHistory[] @relation(name: "PrismaPostHistoryToPrismaUser")
emergencyContacts PrismaEmergencyContact[] @relation(name: "PrismaEmergencyContactToPrismaUser")
passwordResets PrismaPasswordReset[] @relation(name: "PrismaPasswordResetToPrismaUser")
apiKeys PrismaApiKey[] @relation(name: "PrismaApiKeyToPrismaUser")
loginProviders PrismaLoginProvider[] @relation(name: "PrismaUserToPrismaLoginProvider")
passwordHash String @map("password_hash")
passwordSalt String @map("password_salt")
firstName String @map("first_name")
lastName String @map("last_name")
class String
photoUrl String? @map("photo_url")
email String @unique
phone String?
address String?
zipCode String? @map("zip_code")
website String?
luCard String? @unique
dateJoined DateTime @default(now()) @map("date_joined")
verifyInfo PrismaVerifyInfo? @relation(name: "PrismaVerifyInfoToPrismaUser")
username String @id
access PrismaIndividualAccess[] @relation(name: "PrismaIndividualAccessToPrismaUser")
grantedIndividualAccessLog PrismaIndividualAccessLog[] @relation(name: "PrismaIndividualAccessLogToPrismaUserGrantor")
grantedPostAccessLog PrismaPostAccessLog[] @relation(name: "PrismaPostAccessLogToPrismaUserGrantor")
targetIndividualAccessLog PrismaIndividualAccessLog[] @relation(name: "PrismaIndividualAccessLogToPrismaUserTarget")
articles PrismaArticle[] @relation(name: "PrismaArticleToAuthor")
editedArticles PrismaArticle[] @relation(name: "PrismaArticleToLastUpdateBy")
elections PrismaElection[] @relation(name: "PrismaElectionToPrismaUser")
nominations PrismaNomination[] @relation(name: "PrismaNominationToPrismaUser")
proposals PrismaProposal[] @relation(name: "PrismaProposalToPrismaUser")
files PrismaFile[] @relation(name: "PrismaFileToPrismaUser")
heHes PrismaHehe[] @relation(name: "PrismaHeheToPrismaUser")
postHistory PrismaPostHistory[] @relation(name: "PrismaPostHistoryToPrismaUser")
emergencyContacts PrismaEmergencyContact[] @relation(name: "PrismaEmergencyContactToPrismaUser")
passwordResets PrismaPasswordReset[] @relation(name: "PrismaPasswordResetToPrismaUser")
apiKeys PrismaApiKey[] @relation(name: "PrismaApiKeyToPrismaUser")
loginProviders PrismaLoginProvider[] @relation(name: "PrismaUserToPrismaLoginProvider")
passwordHash String @map("password_hash")
passwordSalt String @map("password_salt")
firstName String @map("first_name")
lastName String @map("last_name")
class String
photoUrl String? @map("photo_url")
email String @unique
phone String?
address String?
zipCode String? @map("zip_code")
website String?
luCard String? @unique
dateJoined DateTime @default(now()) @map("date_joined")
verifyInfo PrismaVerifyInfo? @relation(name: "PrismaVerifyInfoToPrismaUser")
@@index([firstName, lastName])
@@map("users")
Expand All @@ -88,6 +89,7 @@ model PrismaPostAccessLog {
resource String
isActive Boolean @map("is_active")
timestamp DateTime @default(now())
@@map("post_accesses_log")
}

Expand All @@ -100,10 +102,10 @@ model PrismaPost {
history PrismaPostHistory[] @relation(name: "PrismaPostToPrismaPostHistory")
sortPriority Int @default(0)
postname String @unique
email String?
utskott PrismaUtskott
description String
spots Int
email String?
utskott PrismaUtskott
description String
spots Int
postType PrismaPostType @map("post_type")
active Boolean @default(true)
interviewRequired Boolean @default(false) @map("interview_required")
Expand Down Expand Up @@ -211,6 +213,7 @@ model PrismaNomination {

model PrismaActivity {
id String @id @default(cuid())
hidden Boolean @default(false)
source PrismaActivitySource
title String
description String?
Expand Down
28 changes: 16 additions & 12 deletions src/api/activity.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,24 @@ export class ActivityAPI {
from: Date,
to: Date,
utskott: Utskott[] = [Utskott.Other],
includeHidden = false,
): Promise<PrismaActivity[]> {
//Acts where (start < to) && ((end > from) || ((start > from) && (end == null)))
const dateFilters = {
startDate: { lte: to },
OR: [{ endDate: { gte: from } }, { AND: [{ startDate: { gte: from } }, { endDate: null }] }],
};

//Only acts in utskott[]
const utskottFilter = { utskott: { in: utskott } };

//If includeHidden, get all acts, else only the visible ones
const hiddenFilter = includeHidden ? {} : { OR: [{ hidden: false }] };

const activities = await prisma.prismaActivity.findMany({
where: {
startDate: {
lte: to,
},
OR: [
{
endDate: {
gte: from,
},
},
{ AND: [{ startDate: { gte: from } }, { endDate: null }] },
],
AND: { utskott: { in: utskott } },
...dateFilters,
AND: [utskottFilter, hiddenFilter],
},
orderBy: { startDate: 'asc' },
});
Expand Down Expand Up @@ -72,6 +75,7 @@ export class ActivityAPI {
imageUrl: activity.imageUrl,
locationTitle: activity.location?.title,
locationLink: activity.location?.link,
hidden: activity.hidden ?? false,
},
});

Expand Down
Loading

0 comments on commit a8c38ce

Please sign in to comment.