Skip to content

Commit fecd5a9

Browse files
committed
feat(company-representatives): add update name functionality for company representatives
1 parent 3156c61 commit fecd5a9

File tree

4 files changed

+39
-7
lines changed

4 files changed

+39
-7
lines changed

backend/src/mongodb/companyReps.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func (c *CompanyRepsType) CreateCompanyRep(data CreateCompanyRepData) (*models.C
102102
if err != nil {
103103
return nil, err
104104
}
105-
105+
106106
dataQuery["contact"] = contact.ID
107107
} else {
108108
contact, err := Contacts.Collection.InsertOne(ctx, bson.M{
@@ -144,10 +144,8 @@ func (c *CompanyRepsType) CreateCompanyRep(data CreateCompanyRepData) (*models.C
144144
func (c *CompanyRepsType) UpdateCompanyRep(id primitive.ObjectID, data CreateCompanyRepData) (*models.CompanyRep, error) {
145145
ctx := context.Background()
146146

147-
var updateQuery = bson.M{
148-
"$set": bson.M{
149-
"name": data.Name,
150-
},
147+
setDoc := bson.M{
148+
"name": data.Name,
151149
}
152150

153151
if data.Contact != nil {
@@ -156,9 +154,12 @@ func (c *CompanyRepsType) UpdateCompanyRep(id primitive.ObjectID, data CreateCom
156154
return nil, err
157155
}
158156

159-
updateQuery["$Set.contact"] = contact.ID
157+
// add contact id to the $set document
158+
setDoc["contact"] = contact.ID
160159
}
161160

161+
var updateQuery = bson.M{"$set": setDoc}
162+
162163
var optionsQuery = options.FindOneAndUpdate()
163164
optionsQuery.SetReturnDocument(options.After)
164165

frontend/src/api/companies.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ export const createCompanyRepresentative = (
6666
export const deleteCompanyRepresentative = (id: string, repId: string) =>
6767
instance.delete(`/companies/${id}/employer/${repId}`);
6868

69+
export const updateCompanyRepresentative = (
70+
repId: string,
71+
data: CreateCompanyRepData,
72+
) => instance.put(`/companyReps/${repId}`, data);
73+
6974
export const updateRepresentativeOrder = (
7075
id: string,
7176
representativeIds: string[],

frontend/src/components/ContactCard.vue

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
<div class="flex-1 overflow-y-auto p-6 min-h-0">
5656
<ContactForm
5757
v-if="contact"
58-
without-name
58+
:without-name="entityType !== 'company'"
5959
mode="edit"
6060
:initial-data="{
6161
id: contact.id,
@@ -247,6 +247,7 @@ import type { Contact } from "@/dto/contacts";
247247
import type { ContactSocials, CreateContactData } from "@/dto/contacts";
248248
import { Gender, Language } from "@/dto/contacts";
249249
import { updateContact } from "@/api/contacts";
250+
import { updateCompanyRepresentative } from "@/api/companies";
250251
import Card from "./ui/card/Card.vue";
251252
import CardContent from "./ui/card/CardContent.vue";
252253
import Badge from "./ui/badge/Badge.vue";
@@ -262,6 +263,7 @@ interface Props {
262263
canDelete?: boolean;
263264
entityId?: string;
264265
entityType?: "company" | "speaker";
266+
repId?: string;
265267
isDeleting?: boolean;
266268
}
267269
@@ -273,6 +275,7 @@ const props = withDefaults(defineProps<Props>(), {
273275
contactName: undefined,
274276
entityId: undefined,
275277
entityType: undefined,
278+
repId: undefined,
276279
});
277280
278281
const emit = defineEmits<{
@@ -330,6 +333,28 @@ const handleUpdateContact = async (data: CreateCompanyRepData) => {
330333
};
331334
332335
updateContactMutation({ id: props.contact.id, data: contactData });
336+
337+
// If this contact is a company representative, also persist the representative's name
338+
// through the companyRep endpoint so the rep name is updated.
339+
if (props.entityType === "company" && props.repId) {
340+
try {
341+
await updateCompanyRepresentative(props.repId, {
342+
name: data.name,
343+
contact: data.contact,
344+
});
345+
346+
// Invalidate representatives query for this company so UI refreshes
347+
if (props.entityId) {
348+
queryCache.invalidateQueries({
349+
key: ["company-representatives", props.entityId],
350+
});
351+
}
352+
} catch (err) {
353+
// Log and continue — contact update already attempted
354+
console.error("Failed to update company representative:", err);
355+
}
356+
}
357+
333358
isEditFormOpen.value = false;
334359
};
335360

frontend/src/components/companies/CompanyContacts.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@
141141
can-delete
142142
:entity-id="companyId"
143143
entity-type="company"
144+
:rep-id="rep.id"
144145
:is-deleting="isDeleting"
145146
:class="{
146147
'ml-2 md:ml-4': isReorderMode,

0 commit comments

Comments
 (0)