@@ -13,13 +13,15 @@ const ORG_TYPES = v.union(
1313 v . literal ( "other" ) ,
1414) ;
1515
16+ type OrgType = "club" | "department" | "official" | "publication" | "company" | "other" ;
17+
1618export const overview = query ( {
1719 args : { token : v . string ( ) } ,
1820 handler : async ( ctx , args ) => {
1921 requireAdminToken ( args . token ) ;
2022
2123 const [ organizations , listservs , messages ] = await Promise . all ( [
22- ctx . db . query ( "organizations " ) . order ( "asc" ) . collect ( ) ,
24+ ctx . db . query ( "orgs " ) . order ( "asc" ) . collect ( ) ,
2325 ctx . db . query ( "listservs" ) . order ( "asc" ) . collect ( ) ,
2426 ctx . db
2527 . query ( "listservMessages" )
@@ -91,7 +93,7 @@ export const createOrganization = mutation({
9193 } ,
9294 handler : async ( ctx , args ) => {
9395 requireAdminToken ( args . token ) ;
94- return getOrCreateOrganization ( ctx , {
96+ return getOrCreateOrg ( ctx , {
9597 name : args . name ,
9698 type : args . type ,
9799 description : cleanOptional ( args . description ) ,
@@ -104,7 +106,7 @@ export const createOrganization = mutation({
104106export const updateOrganization = mutation ( {
105107 args : {
106108 token : v . string ( ) ,
107- organizationId : v . id ( "organizations " ) ,
109+ organizationId : v . id ( "orgs " ) ,
108110 name : v . string ( ) ,
109111 type : ORG_TYPES ,
110112 description : v . optional ( v . string ( ) ) ,
@@ -117,11 +119,11 @@ export const updateOrganization = mutation({
117119 await ctx . db . patch ( args . organizationId , {
118120 name : args . name . trim ( ) ,
119121 slug : slugify ( args . name ) ,
120- type : args . type ,
121- description : cleanOptional ( args . description ) ,
122- website : cleanOptional ( args . website ) ,
122+ orgType : args . type ,
123+ description : cleanOptional ( args . description ) ?? "" ,
124+ websiteUrl : cleanOptional ( args . website ) ,
123125 tags : args . tags ?? [ ] ,
124- status : args . status ,
126+ orgStatus : args . status ,
125127 updatedAt : Date . now ( ) ,
126128 } ) ;
127129 } ,
@@ -131,7 +133,7 @@ export const assignSender = mutation({
131133 args : {
132134 token : v . string ( ) ,
133135 senderEmail : v . string ( ) ,
134- organizationId : v . optional ( v . id ( "organizations " ) ) ,
136+ organizationId : v . optional ( v . id ( "orgs " ) ) ,
135137 organizationName : v . optional ( v . string ( ) ) ,
136138 organizationType : v . optional ( ORG_TYPES ) ,
137139 sourceName : v . optional ( v . string ( ) ) ,
@@ -152,7 +154,7 @@ export const assignSender = mutation({
152154 const suggestion = suggestSource ( senderEmail ) ;
153155 const organizationId =
154156 args . organizationId ??
155- ( await getOrCreateOrganization ( ctx , {
157+ ( await getOrCreateOrg ( ctx , {
156158 name :
157159 cleanOptional ( args . organizationName ) ?? suggestion . organizationName ,
158160 type : args . organizationType ?? suggestion . organizationType ,
@@ -256,7 +258,7 @@ export const assignSourceOrganization = mutation({
256258 args : {
257259 token : v . string ( ) ,
258260 listservId : v . id ( "listservs" ) ,
259- organizationId : v . id ( "organizations " ) ,
261+ organizationId : v . id ( "orgs " ) ,
260262 } ,
261263 handler : async ( ctx , args ) => {
262264 requireAdminToken ( args . token ) ;
@@ -275,42 +277,36 @@ export const assignSourceOrganization = mutation({
275277 } ,
276278} ) ;
277279
278- async function getOrCreateOrganization (
280+ async function getOrCreateOrg (
279281 ctx : MutationCtx ,
280282 params : {
281283 name : string ;
282- type :
283- | "club"
284- | "department"
285- | "official"
286- | "publication"
287- | "company"
288- | "other" ;
284+ type : OrgType ;
289285 description ?: string ;
290286 website ?: string ;
291287 tags : string [ ] ;
292288 } ,
293- ) : Promise < Id < "organizations " > > {
289+ ) : Promise < Id < "orgs " > > {
294290 const name = params . name . trim ( ) ;
295291 if ( ! name ) throw new Error ( "Organization name is required." ) ;
296292
297293 const slug = slugify ( name ) ;
298294 const existing = await ctx . db
299- . query ( "organizations " )
295+ . query ( "orgs " )
300296 . withIndex ( "by_slug" , ( q ) => q . eq ( "slug" , slug ) )
301297 . unique ( ) ;
302298 if ( existing ) return existing . _id ;
303299
304300 const now = Date . now ( ) ;
305- return ctx . db . insert ( "organizations " , {
301+ return ctx . db . insert ( "orgs " , {
306302 name,
307303 slug,
308- type : params . type ,
309- description : params . description ,
310- website : params . website ,
304+ orgType : params . type ,
305+ description : params . description ?? "" ,
306+ websiteUrl : params . website ,
311307 tags : params . tags ,
312- status : "active" ,
313- createdAt : now ,
308+ isVerified : false ,
309+ orgStatus : "active" ,
314310 updatedAt : now ,
315311 } ) ;
316312}
0 commit comments