Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fix-agreement-version-sort.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"adcontextprotocol": patch
---

Fix semantic version sorting for agreements. When multiple agreement versions share the same effective date, the system now correctly selects the highest version (e.g., 1.1.1 before 1.1).
21 changes: 21 additions & 0 deletions server/public/admin-agreements.html
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,22 @@ <h2 id="modalTitle">Edit Agreement</h2>
}
}

// Compare semantic versions (e.g., "1.1.1" > "1.1" > "1.0")
function compareVersions(a, b) {
const partsA = a.split('.').map(Number);
const partsB = b.split('.').map(Number);
const maxLen = Math.max(partsA.length, partsB.length);

for (let i = 0; i < maxLen; i++) {
const numA = partsA[i] || 0;
const numB = partsB[i] || 0;
if (numA !== numB) {
return numB - numA; // Descending order (higher versions first)
}
}
return 0;
}

// Render agreements list
function renderAgreementsList() {
const listDiv = document.getElementById('agreementsList');
Expand All @@ -302,6 +318,11 @@ <h2 id="modalTitle">Edit Agreement</h2>
grouped[agreement.agreement_type].push(agreement);
});

// Sort each group by version (descending - newest first)
Object.keys(grouped).forEach(type => {
grouped[type].sort((a, b) => compareVersions(a.version, b.version));
});

const formatType = (type) => {
const types = {
'terms_of_service': 'Terms of Service',
Expand Down
5 changes: 4 additions & 1 deletion server/src/db/company-db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,10 @@ export class CompanyDatabase {
async getCurrentAgreement(): Promise<Agreement | null> {
const pool = getPool();
const result = await pool.query(
'SELECT * FROM agreements ORDER BY effective_date DESC LIMIT 1'
`SELECT * FROM agreements
ORDER BY effective_date DESC,
string_to_array(version, '.')::int[] DESC
LIMIT 1`
);
return result.rows.length > 0 ? this.mapAgreement(result.rows[0]) : null;
}
Expand Down
11 changes: 9 additions & 2 deletions server/src/db/organization-db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,10 @@ export class OrganizationDatabase {
async getCurrentAgreement(): Promise<Agreement | null> {
const pool = getPool();
const result = await pool.query(
'SELECT * FROM agreements ORDER BY effective_date DESC LIMIT 1'
`SELECT * FROM agreements
ORDER BY effective_date DESC,
string_to_array(version, '.')::int[] DESC
LIMIT 1`
);
return result.rows[0] || null;
}
Expand Down Expand Up @@ -285,7 +288,11 @@ export class OrganizationDatabase {
async getCurrentAgreementByType(type: string): Promise<Agreement | null> {
const pool = getPool();
const result = await pool.query(
'SELECT * FROM agreements WHERE agreement_type = $1 ORDER BY effective_date DESC LIMIT 1',
`SELECT * FROM agreements
WHERE agreement_type = $1
ORDER BY effective_date DESC,
string_to_array(version, '.')::int[] DESC
LIMIT 1`,
[type]
);
return result.rows[0] || null;
Expand Down