MCPcopy Create free account
hub / github.com/TechJeeper/Printventory / initializeDefaultSettings

Function initializeDefaultSettings

main.js:1896–1943  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1894 const tag = resolveTagForMcp(args);
1895 const newName = String(args && args.newName || '').trim();
1896 if (!newName) throw new Error('newName is required');
1897 if (newName.toLowerCase() === String(tag.name).toLowerCase()) {
1898 if (newName !== tag.name) {
1899 db.prepare('UPDATE tags SET name = ? WHERE id = ?').run(newName, tag.id);
1900 }
1901 return { success: true, id: tag.id, name: newName, merged: false };
1902 }
1903 const existing = db.prepare('SELECT id, name FROM tags WHERE name = ? COLLATE NOCASE').get(newName);
1904 if (existing && existing.id !== tag.id) {
1905 db.transaction(() => {
1906 const rows = db.prepare('SELECT model_id FROM model_tags WHERE tag_id = ?').all(tag.id);
1907 const insert = db.prepare('INSERT OR IGNORE INTO model_tags (model_id, tag_id) VALUES (?, ?)');
1908 for (const row of rows) insert.run(row.model_id, existing.id);
1909 db.prepare('DELETE FROM model_tags WHERE tag_id = ?').run(tag.id);
1910 db.prepare('DELETE FROM tags WHERE id = ?').run(tag.id);
1911 if (existing.name !== newName) {
1912 db.prepare('UPDATE tags SET name = ? WHERE id = ?').run(newName, existing.id);
1913 }
1914 })();
1915 return { success: true, id: existing.id, name: newName, merged: true, deletedId: tag.id };
1916 }
1917 db.prepare('UPDATE tags SET name = ? WHERE id = ?').run(newName, tag.id);
1918 return { success: true, id: tag.id, name: newName, merged: false };
1919}
1920
1921const MCP_METADATA_TYPES = new Set(['designer', 'parentModel', 'license']);
1922
1923function renameMetadataForMcp(args) {
1924 const type = String(args && args.type || '').trim();
1925 const oldName = String(args && args.oldName || '').trim();
1926 const newName = String(args && args.newName || '').trim();
1927 if (!MCP_METADATA_TYPES.has(type)) throw new Error('type must be designer, parentModel, or license');
1928 if (!oldName || !newName) throw new Error('oldName and newName are required');
1929 const existing = db.prepare(`
1930 SELECT COUNT(*) as count FROM models
1931 WHERE ${type} = ? AND ${type} IS NOT NULL AND ${type} != ''
1932 `).get(newName);
1933 const existingCount = existing ? existing.count : 0;
1934 const result = db.prepare(`UPDATE models SET ${type} = ? WHERE ${type} = ?`).run(newName, oldName);
1935 return {
1936 success: true,
1937 updated: result.changes,
1938 merged: existingCount > 0,
1939 existingCount
1940 };
1941}
1942
1943function deleteMetadataForMcp(args) {
1944 const type = String(args && args.type || '').trim();
1945 const name = String(args && args.name || '').trim();
1946 if (!MCP_METADATA_TYPES.has(type)) throw new Error('type must be designer, parentModel, or license');

Callers 1

initializeDatabaseFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected