Skip to content

Commit

Permalink
chore: rename all library types
Browse files Browse the repository at this point in the history
  • Loading branch information
benfurber committed Jan 9, 2025
1 parent f4db4cf commit 6337a18
Show file tree
Hide file tree
Showing 33 changed files with 197 additions and 212 deletions.
5 changes: 2 additions & 3 deletions functions/src/emailNotifications/createModerationEmails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import { getUserAndEmail } from './utils'

import type { QueryDocumentSnapshot } from 'firebase-admin/firestore'
import type { Change } from 'firebase-functions/v1'
import type { IModerable } from 'oa-shared'
import type { IHowtoDB } from 'oa-shared/models/howto'
import type { ILibrary, IModerable } from 'oa-shared'
import type { IMapPin } from 'oa-shared/models/maps'

export async function handleModerationUpdate<T extends IModerable>(
Expand All @@ -27,7 +26,7 @@ export async function handleModerationUpdate<T extends IModerable>(
}
}

export async function createHowtoModerationEmail(howto: IHowtoDB) {
export async function createHowtoModerationEmail(howto: ILibrary.DB) {
const { toUser, toUserEmail } = await getUserAndEmail(howto._createdBy)

if (howto.moderation === IModerationStatus.ACCEPTED) {
Expand Down
7 changes: 3 additions & 4 deletions functions/src/emailNotifications/createSubmissionEmails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ import {
getSenderMessageEmail,
} from './templateHelpers'
import { getUserAndEmail, isValidMessageRequest } from './utils'
import { IMessageDB } from 'oa-shared/models/messages'
import { IHowtoDB } from 'oa-shared/models/howto'
import { IMapPin } from 'oa-shared/models/maps'

import type { ILibrary, IMapPin, IMessageDB } from 'oa-shared'

export async function createMessageEmails(message: IMessageDB) {
const isValid = await isValidMessageRequest(message)
Expand All @@ -38,7 +37,7 @@ export async function createMessageEmails(message: IMessageDB) {
}
}

export async function createHowtoSubmissionEmail(howto: IHowtoDB) {
export async function createHowtoSubmissionEmail(howto: ILibrary.DB) {
const { toUser, toUserEmail } = await getUserAndEmail(howto._createdBy)

if (howto.moderation === IModerationStatus.AWAITING_MODERATION) {
Expand Down
27 changes: 15 additions & 12 deletions functions/src/emailNotifications/templateHelpers.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import { getEmailHtml } from './templates/index'
import { NOTIFICATION_LIST_IMAGE } from './constants'
import {
getNotificationListItem,
getProjectImageSrc,
SITE_URL,
getProjectName,
getNotificationListItem,
getProjectSignoff,
SITE_URL,
} from './utils'
import { getEmailHtml } from './templates/index'
import { IUserDB } from 'oa-shared/models/user'
import { INotification } from 'oa-shared/models/notifications'
import { IHowtoDB } from 'oa-shared/models/howto'
import { IMapPin } from 'oa-shared/models/maps'
import { IMessageDB } from 'oa-shared/models/messages'

import type {
ILibrary,
IMapPin,
IMessageDB,
INotification,
IUserDB,
} from 'oa-shared'

export interface Email {
html: string
Expand Down Expand Up @@ -137,7 +140,7 @@ export const getNotificationEmail = (
export const HOW_TO_APPROVAL_SUBJECT = 'Your project has been approved!'
export const getHowToApprovalEmail = (
user: IUserDB,
howto: IHowtoDB,
howto: ILibrary.DB,
): Email => {
return {
html: getEmailHtml('how-to-approval', {
Expand Down Expand Up @@ -186,7 +189,7 @@ export const getSenderMessageEmail = ({
export const HOW_TO_SUBMISSION_SUBJECT = 'Your project has been submitted'
export const getHowToSubmissionEmail = (
user: IUserDB,
howto: IHowtoDB,
howto: ILibrary.DB,
): Email => {
return {
html: getEmailHtml('how-to-submission', {
Expand Down Expand Up @@ -237,7 +240,7 @@ export const getUserVerifiedBadgeAddedEmail = (user: IUserDB): Email => ({
export const HOW_TO_REJECTED_SUBJECT = 'Your project has been rejected'
export const getHowToRejectedEmail = (
user: IUserDB,
howto: IHowtoDB,
howto: ILibrary.DB,
): Email => ({
subject: HOW_TO_REJECTED_SUBJECT,
html: getEmailHtml('how-to-rejected', {
Expand All @@ -260,7 +263,7 @@ export const HOW_TO_NEEDS_IMPROVEMENTS_SUBJECT =
'Your project needs improvements'
export const getHowToNeedsImprovementsEmail = (
user: IUserDB,
howto: IHowtoDB,
howto: ILibrary.DB,
): Email => ({
subject: HOW_TO_NEEDS_IMPROVEMENTS_SUBJECT,
html: getEmailHtml('how-to-needs-improvements', {
Expand Down
9 changes: 4 additions & 5 deletions functions/src/emulator/seed/content-generate.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { DifficultyLevel, IModerationStatus } from 'oa-shared'
import { MOCK_AUTH_USERS } from 'oa-shared/mocks/auth'

import { setDoc, updateDoc } from '../../Firebase/firestoreDB'

import type { ILibrary, IUserDB } from 'oa-shared'
import type { IMockAuthUser } from 'oa-shared/mocks/auth'
import { DifficultyLevel, IHowtoDB } from 'oa-shared/models/howto'
import { IModerationStatus } from 'oa-shared'
import { IUserDB } from 'oa-shared/models/user'

/**
* Populate additional mock howtos alongside production data for ease of testing
Expand All @@ -22,11 +21,11 @@ export async function seedContentGenerate() {

export function getMockHowto(
uid: string,
moderation: IHowtoDB['moderation'] = IModerationStatus.ACCEPTED,
moderation: ILibrary.DB['moderation'] = IModerationStatus.ACCEPTED,
) {
const _id = `00_${uid}_howto`
const loginInfo = `username : ${uid}@example.com\npassword : ${uid}`
const howto: IHowtoDB = {
const howto: ILibrary.DB = {
_id,
_created: new Date().toISOString(),
_modified: new Date().toISOString(),
Expand Down
4 changes: 2 additions & 2 deletions packages/cypress/src/fixtures/howto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { DifficultyLevel, IModerationStatus } from 'oa-shared'

import { generateAlphaNumeric } from '../utils/TestUtils'

import type { IHowtoDB } from 'oa-shared'
import type { ILibrary } from 'oa-shared'

const _id = generateAlphaNumeric(20)
const _created = dateformat(Date.now(), 'yyyy-mm-dd')

export const howto: IHowtoDB = {
export const howto: ILibrary.DB = {
_id,
_deleted: false,
_createdBy: 'howto_super_user',
Expand Down
12 changes: 3 additions & 9 deletions packages/cypress/src/support/CustomAssertations.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import chaiSubset from 'chai-subset'

import type {
IHowto,
IHowtoStep,
IResearchDB,
IUserDB,
ProfileTypeName,
} from 'oa-shared'
import type { ILibrary, IResearchDB, IUserDB, ProfileTypeName } from 'oa-shared'

declare global {
namespace Chai {
Expand Down Expand Up @@ -37,7 +31,7 @@ chai.use((chaiObj) => {

const eqHowto = (chaiObj) => {
function compare(this: any, expected: any) {
const subject: IHowto = this._obj
const subject: ILibrary.Item = this._obj
const {
_createdBy,
_deleted,
Expand Down Expand Up @@ -90,7 +84,7 @@ const eqHowto = (chaiObj) => {
}
const eqHowtoStep = (chaiObj) => {
function compare(this: any, expected: any, index: number) {
const subject: IHowtoStep = this._obj
const subject: ILibrary.Step = this._obj
const { _animationKey, text, title } = expected
expect(subject, `Step ${index} with info`).to.containSubset({
_animationKey,
Expand Down
4 changes: 2 additions & 2 deletions packages/cypress/src/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { deleteDB } from 'idb'

import { Auth, TestDB } from './db/firebase'

import type { IHowtoDB, IQuestionDB, IResearchDB } from 'oa-shared'
import type { ILibrary, IQuestionDB, IResearchDB } from 'oa-shared'
import type { IUserSignUpDetails } from '../utils/TestUtils'
import type { firebase } from './db/firebase'

Expand Down Expand Up @@ -33,7 +33,7 @@ declare global {
opStr: any,
value: string,
): Chainable<any[]>
addHowto(howto: IHowtoDB, user: IUserSignUpDetails): Chainable<void>
addHowto(howto: ILibrary.DB, user: IUserSignUpDetails): Chainable<void>
addQuestion(
question: IQuestionDB,
user: IUserSignUpDetails,
Expand Down
78 changes: 0 additions & 78 deletions shared/models/howto.ts

This file was deleted.

2 changes: 1 addition & 1 deletion shared/models/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export * from './common'
export * from './db'
export * from './howto'
export * from './library'
export * from './maps'
export * from './notifications'
export * from './research'
Expand Down
78 changes: 78 additions & 0 deletions shared/models/library.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import type { ICategory } from './categories'
import type { IConvertedFileMeta } from './common'
import type { DBDoc } from './db'
import type { IModerable } from './moderation'
import type { IUploadedFileMeta } from './storage'
import type { ISelectedTags } from './tags'
import type { UserMention } from './user'
import type { ISharedFeatures } from './voteUseful'

export enum DifficultyLevel {
EASY = 'Easy',
MEDIUM = 'Medium',
HARD = 'Hard',
VERY_HARD = 'Very Hard',
}

export declare namespace ILibrary {
type DB = ILibrary.Item & DBDoc

interface FormInput extends IModerable, ISharedFeatures {
slug: string
title: string
allowDraftSave?: boolean
category?: ICategory

// NOTE cover image input starts as convertedFileMeta but is transformed on upload
cover_image?: IUploadedFileMeta | IConvertedFileMeta
cover_image_alt?: string

// Added to be able to recover on edit by admin
creatorCountry?: string
totalComments?: number
latestCommentDate?: string
description?: string
difficulty_level?: DifficultyLevel
files?: Array<IUploadedFileMeta | File | null>
fileLink?: string
mentions?: UserMention[]
steps: StepInput[]

// note, tags will remain optional as if populated {} will be stripped by db (firestore)
tags?: ISelectedTags
time?: string
}

interface Item extends FormInput {
_createdBy: string
_deleted: boolean
cover_image?: IUploadedFileMeta
cover_image_alt?: string
fileLink?: string
total_downloads?: number
latestCommentDate?: string | undefined
mentions: UserMention[]
previousSlugs: string[]
totalComments: number
totalUsefulVotes?: number
keywords?: string[]
}

interface StepInput {
images?: Array<IUploadedFileMeta | IConvertedFileMeta | null>
title?: string
text?: string
videoUrl?: string
_animationKey?: string
}

interface Step extends StepInput {
images?: Array<IUploadedFileMeta | null>
videoUrl?: string
title?: string
text?: string

// *** NOTE - adding an '_animationKey' field to track when specific array element removed for
_animationKey?: string
}
}
4 changes: 2 additions & 2 deletions src/pages/Howto/Content/Common/Howto.form.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { describe, expect, it, vi } from 'vitest'

import { HowtoForm } from './Howto.form'

import type { IHowtoDB } from 'oa-shared'
import type { ILibrary } from 'oa-shared'
import type { ParentType } from './Howto.form'

const Theme = testingThemeStyles
Expand Down Expand Up @@ -161,7 +161,7 @@ describe('Howto form', () => {
})
})

const Wrapper = (formValues: IHowtoDB, parentType: ParentType, navProps) => {
const Wrapper = (formValues: ILibrary.DB, parentType: ParentType, navProps) => {
const ReactStub = createRemixStub(
[
{
Expand Down
Loading

0 comments on commit 6337a18

Please sign in to comment.