@@ -26,7 +26,7 @@ type CompaniesType struct {
2626// Cached version of the public companies for the current event
2727var currentPublicCompanies * []* models.CompanyPublic
2828
29- //ResetCurrentPublicCompanies resets current public companies
29+ // ResetCurrentPublicCompanies resets current public companies
3030func ResetCurrentPublicCompanies () {
3131 currentPublicCompanies = nil
3232}
@@ -76,17 +76,17 @@ func (c *CompaniesType) CreateCompany(data CreateCompanyData) (*models.Company,
7676 },
7777 "mails" : []models.ContactMail {},
7878 })
79- if err != nil {
80- return nil , err
81- }
79+ if err != nil {
80+ return nil , err
81+ }
8282
8383 insertResult , err := c .Collection .InsertOne (ctx , bson.M {
8484 "name" : data .Name ,
8585 "description" : data .Description ,
8686 "site" : data .Site ,
8787 "employers" : []primitive.ObjectID {},
8888 "participations" : []models.CompanyParticipation {},
89- "contact" : createdContact .InsertedID .(primitive.ObjectID ),
89+ "contact" : createdContact .InsertedID .(primitive.ObjectID ),
9090 })
9191
9292 if err != nil {
@@ -316,11 +316,11 @@ func companyToPublic(company models.Company, eventID *int) (*models.CompanyPubli
316316 var participationObj models.CompanyParticipationPublic
317317
318318 participationObj = models.CompanyParticipationPublic {
319- Event : p .Event ,
320- Partner : participation .Partner ,
321- Package : models.PackagePublic {},
322- StandDetails : participation .StandDetails ,
323- Stands : participation .Stands ,
319+ Event : p .Event ,
320+ Partner : participation .Partner ,
321+ Package : models.PackagePublic {},
322+ StandDetails : participation .StandDetails ,
323+ Stands : participation .Stands ,
324324 }
325325
326326 if participation .Package != nil {
@@ -732,16 +732,20 @@ func (c *CompaniesType) UpdateCompanyParticipation(companyID primitive.ObjectID,
732732 return nil , err
733733 }
734734
735- var updateQuery = bson.M {
736- "$set" : bson.M {
737- "participations.$.member" : * data .Member ,
738- "participations.$.partner" : * data .Partner ,
739- "participations.$.notes" : * data .Notes ,
740- },
735+ setFields := bson.M {
736+ "participations.$.member" : * data .Member ,
737+ "participations.$.partner" : * data .Partner ,
738+ "participations.$.notes" : * data .Notes ,
741739 }
742740
743741 if data .Confirmed != nil {
744- updateQuery ["participations.$.confirmed" ] = data .Confirmed .UTC ()
742+ setFields ["participations.$.confirmed" ] = data .Confirmed .UTC ()
743+ } else {
744+ setFields ["participations.$.confirmed" ] = nil
745+ }
746+
747+ var updateQuery = bson.M {
748+ "$set" : setFields ,
745749 }
746750
747751 var filterQuery = bson.M {"_id" : companyID , "participations.event" : currentEvent .ID }
@@ -937,39 +941,39 @@ func (c *CompaniesType) UpdateCompanyPublicImage(companyID primitive.ObjectID, u
937941func (c * CompaniesType ) DeleteCompany (companyID primitive.ObjectID ) (* models.Company , error ) {
938942
939943 ctx := context .Background ()
940- var company models.Company
944+ var company models.Company
941945
942946 currentCompany , err := Companies .GetCompany (companyID )
943947 if err != nil {
944948 return nil , err
945949 }
946950
947- for _ , participation := range currentCompany .Participations {
948- _ , err := c .DeleteCompanyParticipation (companyID , participation .Event )
949- if err != nil {
950- return nil , err
951- }
952- }
951+ for _ , participation := range currentCompany .Participations {
952+ _ , err := c .DeleteCompanyParticipation (companyID , participation .Event )
953+ if err != nil {
954+ return nil , err
955+ }
956+ }
953957
954- sessions , err := Sessions .GetSessions (GetSessionsOptions {Company : & companyID })
958+ sessions , err := Sessions .GetSessions (GetSessionsOptions {Company : & companyID })
955959 if err != nil {
956960 return nil , err
957961 }
958962
959- for _ , session := range sessions {
960- _ , err := Sessions .DeleteSession (session .ID )
961- if err != nil {
962- return nil , err
963- }
964- }
963+ for _ , session := range sessions {
964+ _ , err := Sessions .DeleteSession (session .ID )
965+ if err != nil {
966+ return nil , err
967+ }
968+ }
965969
966- err = c .Collection .FindOneAndDelete (ctx , bson.M {"_id" : companyID }).Decode (& company )
967- if err != nil {
968- return nil , err
969- }
970+ err = c .Collection .FindOneAndDelete (ctx , bson.M {"_id" : companyID }).Decode (& company )
971+ if err != nil {
972+ return nil , err
973+ }
970974
971- // Ignore error, if contact doesn't exist, it's ok.
972- Contacts .DeleteContact (company .Contact )
975+ // Ignore error, if contact doesn't exist, it's ok.
976+ Contacts .DeleteContact (company .Contact )
973977
974978 return & company , nil
975979}
@@ -1297,45 +1301,44 @@ func (c *CompaniesType) RemoveCompanyParticipationBilling(companyID primitive.Ob
12971301
12981302// DeleteCompanyParticipation deletes a company's participation related to the eventID
12991303func (c * CompaniesType ) DeleteCompanyParticipation (companyID primitive.ObjectID , eventID int ) (* models.Company , error ) {
1300- ctx := context .Background ();
1301- var updatedCompany models.Company
1302-
1303- company , err := c .GetCompany (companyID )
1304- if err != nil {
1305- return nil , err
1306- }
1307-
1308- for _ , p := range company .Participations {
1309- if p .Event == eventID {
1310- for _ , communication := range p .Communications {
1311- _ , err := c .DeleteCompanyThread (companyID , communication )
1312- if err != nil {
1313- return nil , err
1314- }
1315- }
1316- }
1317- }
1318-
1319- var updateQuery = bson.M {
1320- "$pull" : bson.M {
1321- "participations" : bson.M {
1322- "event" : eventID ,
1323- },
1324- },
1325- }
1326-
1327- var filterQuery = bson.M {"_id" : companyID }
1328-
1329- var optionsQuery = options .FindOneAndUpdate ()
1330- optionsQuery .SetReturnDocument (options .After )
1331-
1332- if err := c .Collection .FindOneAndUpdate (ctx , filterQuery , updateQuery , optionsQuery ).Decode (& updatedCompany ); err != nil {
1333- return nil , err
1334- }
1335-
1336- return & updatedCompany , nil
1337- }
1304+ ctx := context .Background ()
1305+ var updatedCompany models.Company
1306+
1307+ company , err := c .GetCompany (companyID )
1308+ if err != nil {
1309+ return nil , err
1310+ }
1311+
1312+ for _ , p := range company .Participations {
1313+ if p .Event == eventID {
1314+ for _ , communication := range p .Communications {
1315+ _ , err := c .DeleteCompanyThread (companyID , communication )
1316+ if err != nil {
1317+ return nil , err
1318+ }
1319+ }
1320+ }
1321+ }
13381322
1323+ var updateQuery = bson.M {
1324+ "$pull" : bson.M {
1325+ "participations" : bson.M {
1326+ "event" : eventID ,
1327+ },
1328+ },
1329+ }
1330+
1331+ var filterQuery = bson.M {"_id" : companyID }
1332+
1333+ var optionsQuery = options .FindOneAndUpdate ()
1334+ optionsQuery .SetReturnDocument (options .After )
1335+
1336+ if err := c .Collection .FindOneAndUpdate (ctx , filterQuery , updateQuery , optionsQuery ).Decode (& updatedCompany ); err != nil {
1337+ return nil , err
1338+ }
1339+
1340+ return & updatedCompany , nil
1341+ }
13391342
13401343// FindThread finds a thread in a company
13411344func (c * CompaniesType ) FindThread (threadID primitive.ObjectID ) (* models.Company , error ) {
0 commit comments