-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add types for typesense documents
- Loading branch information
1 parent
97fb6a3
commit fea02bf
Showing
11 changed files
with
240 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { type CollectionCreateSchema } from 'typesense/lib/Typesense/Collections'; | ||
|
||
import { db } from '~/server/db'; | ||
|
||
export const clubsSchema: CollectionCreateSchema = { | ||
name: 'clubs', | ||
fields: [ | ||
{ name: 'alias', type: 'string', optional: true }, | ||
{ name: 'name', type: 'string' }, | ||
{ name: 'tagline', type: 'string' }, | ||
{ name: 'urlName', type: 'string' }, | ||
], | ||
}; | ||
|
||
export const populateClubs = async () => { | ||
return await db.query.clubs.findMany({ | ||
columns: { alias: true, name: true, tagline: true, urlName: true }, | ||
}); | ||
}; | ||
|
||
export type ClubsDocumentSchema = Awaited< | ||
ReturnType<typeof populateClubs> | ||
>[number]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { type CollectionCreateSchema } from 'typesense/lib/Typesense/Collections'; | ||
|
||
import { db } from '~/server/db'; | ||
|
||
export const committeesSchema: CollectionCreateSchema = { | ||
name: 'committees', | ||
fields: [ | ||
{ name: 'committeeType', type: 'string' }, | ||
{ name: 'name', type: 'string' }, | ||
{ name: 'nomination', type: 'string', optional: true }, | ||
{ name: 'servingAs', type: 'string' }, | ||
], | ||
}; | ||
|
||
export const populateCommittees = async () => { | ||
return await db.query.committeeMembers.findMany({ | ||
columns: { | ||
committeeType: true, | ||
name: true, | ||
nomination: true, | ||
servingAs: true, | ||
}, | ||
}); | ||
}; | ||
|
||
export type CommitteesDocumentSchema = Awaited< | ||
ReturnType<typeof populateCommittees> | ||
>[number]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { type CollectionCreateSchema } from 'typesense/lib/Typesense/Collections'; | ||
|
||
import { db } from '~/server/db'; | ||
|
||
export const coursesSchema: CollectionCreateSchema = { | ||
name: 'courses', | ||
fields: [ | ||
{ name: 'code', type: 'string' }, | ||
{ name: 'title', type: 'string' }, | ||
], | ||
}; | ||
|
||
export const populateCourses = async () => { | ||
return await db.query.courses.findMany({ | ||
columns: { code: true, title: true }, | ||
}); | ||
}; | ||
|
||
export type CoursesDocumentSchema = Awaited< | ||
ReturnType<typeof populateCourses> | ||
>[number]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { type CollectionCreateSchema } from 'typesense/lib/Typesense/Collections'; | ||
|
||
import { db } from '~/server/db'; | ||
|
||
export const departmentsSchema: CollectionCreateSchema = { | ||
name: 'departments', | ||
fields: [ | ||
{ name: 'name', type: 'string' }, | ||
{ name: 'majors', type: 'string[]' }, | ||
{ name: 'urlName', type: 'string' }, | ||
], | ||
}; | ||
|
||
export const populateDepartments = async () => { | ||
return ( | ||
await db.query.departments.findMany({ | ||
columns: { name: true, urlName: true }, | ||
with: { majors: { columns: { name: true } } }, | ||
}) | ||
).map(({ name, majors, urlName }) => ({ | ||
name, | ||
majors: majors.map(({ name }) => name), | ||
urlName, | ||
})); | ||
}; | ||
|
||
export type DepartmentsDocumentSchema = Awaited< | ||
ReturnType<typeof populateDepartments> | ||
>[number]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { type CollectionCreateSchema } from 'typesense/lib/Typesense/Collections'; | ||
|
||
import { db } from '~/server/db'; | ||
|
||
export const facultySchema: CollectionCreateSchema = { | ||
name: 'faculty', | ||
fields: [ | ||
{ name: 'designation', type: 'string', index: false, optional: true }, | ||
{ name: 'email', type: 'string' }, | ||
{ name: 'employeeId', type: 'string', index: false, optional: true }, | ||
{ name: 'name', type: 'string' }, | ||
{ name: 'officeAddress', type: 'string', index: false, optional: true }, | ||
{ name: 'telephone', type: 'string' }, | ||
], | ||
}; | ||
|
||
export const populateFaculty = async () => { | ||
return ( | ||
await db.query.faculty.findMany({ | ||
columns: { designation: true, employeeId: true, officeAddress: true }, | ||
with: { | ||
person: { columns: { email: true, name: true, telephone: true } }, | ||
}, | ||
}) | ||
).map(({ designation, employeeId, officeAddress, person }) => ({ | ||
designation, | ||
email: person.email, | ||
employeeId, | ||
name: person.name, | ||
officeAddress, | ||
telephone: person.telephone, | ||
})); | ||
}; | ||
|
||
export type FacultyDocumentSchema = Awaited< | ||
ReturnType<typeof populateFaculty> | ||
>[number]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { clubsSchema } from './clubs'; | ||
import { committeesSchema } from './committees'; | ||
import { coursesSchema } from './courses'; | ||
import { departmentsSchema } from './departments'; | ||
import { facultySchema } from './faculty'; | ||
import { sectionsSchema } from './sections'; | ||
import { staffSchema } from './staff'; | ||
|
||
export const schema = { | ||
clubs: clubsSchema, | ||
committees: committeesSchema, | ||
courses: coursesSchema, | ||
departments: departmentsSchema, | ||
faculty: facultySchema, | ||
sections: sectionsSchema, | ||
staff: staffSchema, | ||
}; | ||
|
||
export * from './clubs'; | ||
export * from './committees'; | ||
export * from './courses'; | ||
export * from './departments'; | ||
export * from './faculty'; | ||
export * from './sections'; | ||
export * from './staff'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { type CollectionCreateSchema } from 'typesense/lib/Typesense/Collections'; | ||
|
||
import { db } from '~/server/db'; | ||
|
||
export const sectionsSchema: CollectionCreateSchema = { | ||
name: 'sections', | ||
fields: [ | ||
{ name: 'email', type: 'string' }, | ||
{ name: 'name', type: 'string' }, | ||
{ name: 'urlName', type: 'string' }, | ||
], | ||
}; | ||
|
||
export const populateSections = async () => { | ||
return await db.query.sections.findMany({ | ||
columns: { email: true, name: true, urlName: true }, | ||
}); | ||
}; | ||
|
||
export type SectionsDocumentSchema = Awaited< | ||
ReturnType<typeof populateSections> | ||
>[number]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { type CollectionCreateSchema } from 'typesense/lib/Typesense/Collections'; | ||
|
||
import { db } from '~/server/db'; | ||
|
||
export const staffSchema: CollectionCreateSchema = { | ||
name: 'staff', | ||
fields: [ | ||
{ name: 'designation', type: 'string', index: false, optional: true }, | ||
{ name: 'email', type: 'string' }, | ||
{ name: 'employeeId', type: 'string', index: false, optional: true }, | ||
{ name: 'name', type: 'string' }, | ||
{ name: 'telephone', type: 'string' }, | ||
], | ||
}; | ||
|
||
export const populateStaff = async () => { | ||
return ( | ||
await db.query.staff.findMany({ | ||
columns: { designation: true, employeeId: true }, | ||
with: { | ||
person: { columns: { email: true, name: true, telephone: true } }, | ||
}, | ||
}) | ||
).map(({ designation, employeeId, person }) => ({ | ||
designation, | ||
email: person.email, | ||
employeeId, | ||
name: person.name, | ||
telephone: person.telephone, | ||
})); | ||
}; | ||
|
||
export type StaffDocumentSchema = Awaited< | ||
ReturnType<typeof populateStaff> | ||
>[number]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters