Skip to content

Commit

Permalink
feat: store user team, improve image logic
Browse files Browse the repository at this point in the history
  • Loading branch information
rutmanz committed Sep 1, 2024
1 parent 1a959ff commit ecf9d31
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 21 deletions.
3 changes: 2 additions & 1 deletion MAINTAINING.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ Alternatively use the onboarding button on the app home

## Creating Accounts

To create an account,
To create an account,
Role should be "read" "write" or "admin"

```
npm run createaccount youruser yourpassword role
```
Expand Down
19 changes: 8 additions & 11 deletions dev/create_account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,26 @@ import logger from '~lib/logger'

const prisma = new PrismaClient()




async function main() {
await createUser(process.argv[2].trim(), process.argv[3].trim(), level[0], level[1])
}

const levels:Record<string, [boolean, boolean]> = {
"admin": [true, true],
"write": [true, false],
"read": [false, false]
const levels: Record<string, [boolean, boolean]> = {
admin: [true, true],
write: [true, false],
read: [false, false]
}
console.log("-------")
if (process.argv.length < 5 || process.argv[2].length < 2 || process.argv[3].length<2 || process.argv[4].length < 2) {
console.log('-------')
if (process.argv.length < 5 || process.argv[2].length < 2 || process.argv[3].length < 2 || process.argv[4].length < 2) {
console.log(process.argv)
console.warn("!Missing arguments")
console.warn('!Missing arguments')
process.exit(1)
}
const level = levels[process.argv[4].trim()]

if (levels[process.argv[4]] == null) {
console.log(process.argv)
console.warn("Invalid level")
console.warn('Invalid level')
process.exit(1)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "Members" ADD COLUMN "is_primary_team" BOOLEAN NOT NULL DEFAULT true;
1 change: 1 addition & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ model Member {
slack_photo String? @db.VarChar(255)
slack_photo_small String? @db.VarChar(255)
fallback_photo String? @db.VarChar(255)
is_primary_team Boolean @default(true)
active Boolean @default(true)
createdAt DateTime @default(now()) @db.Timestamptz(6)
Expand Down
13 changes: 9 additions & 4 deletions src/lib/util.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import type { Member } from '@prisma/client'

export function getMemberPhoto(member: Pick<Member, 'slack_photo' | 'slack_photo_small' | 'fallback_photo' | 'use_slack_photo'>, small: boolean = false): string | null {
if (member.use_slack_photo) {
return (small ? member.slack_photo_small : member.slack_photo) ?? member.fallback_photo
} else {
return member.fallback_photo
let slackPhoto = member.slack_photo
let schoolPhoto = member.fallback_photo
if (small) {
schoolPhoto = schoolPhoto?.replace('w_300,h_300', 'w_40,h_40') ?? null
slackPhoto = member.slack_photo_small ?? slackPhoto
}
if (slackPhoto) {
return slackPhoto ?? schoolPhoto
}
return schoolPhoto
}

export function safeParseInt(value: unknown): number | undefined {
Expand Down
2 changes: 1 addition & 1 deletion src/routes/admin/membercerts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Hono } from 'hono'
import prisma from '~lib/prisma'
import { scheduleCertAnnouncement } from '~tasks/certs'

export const router = new Hono().basePath('/membercerts')
export const router = new Hono().basePath('/membercerts/')

export const cert_colors = [
'bg-red-200 border-red-500 accent-red-400', //
Expand Down
2 changes: 2 additions & 0 deletions src/slack/blocks/member/user_hours.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export async function getUserHourSummaryBlocks(user: Prisma.MemberWhereUniqueInp
Blocks.Divider(),
Blocks.Section().fields('External', hours.external.toFixed(1)),
Blocks.Divider(),
Blocks.Section().fields('Meeting', hours.meeting.toFixed(1)),
Blocks.Divider(),
Blocks.Section().fields('Event', hours.event.toFixed(1)),
Blocks.Divider(),
Blocks.Section().fields('Summer', hours.summer.toFixed(1)),
Expand Down
5 changes: 3 additions & 2 deletions src/spreadsheet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ export async function updateSheet() {
'QualifyingHours',
'TotalHours',
'WeeklyHours',
'IsPrimaryTeam',
'Photo',
'Certifications',
'FirstRegistered'
'Certifications'
] as const
const columns = Object.fromEntries(headers.map((h, i) => [h, i])) as Record<(typeof headers)[number], number>
const rows: (string | number)[][] = []
Expand All @@ -81,6 +81,7 @@ export async function updateSheet() {
row[columns.WeeklyHours] = weeklyHours[m.email] ?? 0
row[columns.Photo] = getMemberPhoto(m, true) ?? ''
row[columns.Certifications] = certMap[m.email]?.join(', ')
row[columns.IsPrimaryTeam] = m.is_primary_team
rows.push(row)

if (hours.qualifying >= 50) {
Expand Down
8 changes: 7 additions & 1 deletion src/views/admin_members/grid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,18 @@ export function getColumns(params: { photo_column_formatter?: unknown }) {
editable: true,
headerName: 'Slack Photo Approved',
initialWidth: 100
},
{
field: 'is_primary_team',
editable: true,
headerName: 'Primary Team?',
initialWidth: 100
}
]
if (params.photo_column_formatter) {
out.unshift({
headerName: '',
valueGetter: (params) => getMemberPhoto(params.data as never) ?? '',
valueGetter: (params) => getMemberPhoto(params.data as never, true) ?? '',
editable: false,
cellRenderer: params.photo_column_formatter,
initialWidth: 100
Expand Down
2 changes: 1 addition & 1 deletion src/views/admin_members/new_member.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'ag-grid-community/styles/ag-theme-quartz.min.css'
import { toTitleCase } from '~lib/util'
import { getColumns } from '~views/admin_members/grid'

const getDefaultRow = () => ({ use_slack_photo: false }) as never
const getDefaultRow = () => ({ use_slack_photo: false, is_primary_team: false }) as never
export async function initNewMemberTable(mainTable: GridApi) {
class ButtonComponent implements ag.ICellRendererComp<Prisma.Member> {
private eGui!: HTMLElement
Expand Down

0 comments on commit ecf9d31

Please sign in to comment.